用户资料的联系表 [英] Contact Form for User Profile
问题描述
目前我有一个用户的个人资料。和一般的联系表格模型,它是无表格的,不保存任何数据库。
我的目标是拥有一般的联系表单,我可以在其中链接单个用户配置文件上的联系人按钮。提交时的联系表单将发送到配置文件属性中指定的用户电子邮件。所以例如配置文件有一个字段t.string contact_email。
目前,我将联系人模型设置在哪里可以发送到一个单独的电子邮件。主要是应用程序的所有者。
class ContactMailer< ApplicationMailer
默认值:to => stephen@example.com
def contact_me(msg)
@msg = msg
邮件来自:@ msg.email,主题:@ msg.subject ,body:@ msg.content
end
end
我的目标是只需链接
default:to => stephen@example.com
像
default:to => @ profile.contact_email
我不知道如何为表单指定用户,可能。该过程必须包括一旦访问者点击联系我们,表单接收个人资料电子邮件并将其用作收件人。
对不起,如果这看起来像我没有任何表回答我只是在寻找一个可能在哪里开始或如何完成的提示。
注意:Don不要说这个东西,你必须在默认情况下指定到
。您可以在邮件
方法中将发送到
,就像从 c>, subject
和其他变量。
有几种方法可以实现:
1)您可以使用 hidden_field_tag
传递该用户的电子邮件,如下所示
<%= hidden_field_tag:contact_email,@ user.contact_email%>
然后在服务器端,您可以通过 parmas [ contact_email]
。
2)当您可以致电 contact_me $ c时,您可以发送该用户的电子邮件$ C>。现在,您只发送一个参数
msg
。因此,
def contact_me(msg,to)
@msg = msg
邮件to:to,from:@ msg.email,subject:@ msg.subject,body:@ msg.content
end
当您调用 contact_me
时,您可以执行以下操作:虽然它可能会有所不同,具体取决于您的代码中的实际实现,但概念将始终相同。
I been struggling of thinking of a way to complete this function.
Currently I have a user with a profile. And a general Contact form model that is table-less and doesn't save anything to the database.
My goal is to have a general contact form, In which I can link a contact button on a individual user profile. That contact form when submitted will be sent to the user email specified in the profile attribute. So for example the profile has a field t.string contact_email.
Currently I have the contact model set up where it can send to one individual email. Mainly the app owner.
class ContactMailer < ApplicationMailer
default :to => "stephen@example.com"
def contact_me(msg)
@msg = msg
mail from: @msg.email, subject: @msg.subject, body: @msg.content
end
end
My goal is to simply link the
default :to => "stephen@example.com"
to something like
default :to => "@profile.contact_email"
I have no idea how to specify the user for the form or if its possible. The process would have to include once the visitor hits contact us the form takes the profile email and uses it as the recipient.
Sorry if this seems like I brung nothing to table to answering I'm just looking for a tip on maybe where to start or how it could be done.
Note: Don't get into this thing that you would have to specify to
in default. You can simply send to
in mail
method like you are sending from
, subject
and other variables.
There are several ways to do it:
1) You can use hidden_field_tag
to pass along the email of that user like following
<%= hidden_field_tag :contact_email, @user.contact_email %>
And then on server side, you can have its value through parmas[:contact_email]
.
2) You can send the email of the user when you can call contact_me
. Right now, you are only sending one parameter msg
. So,
def contact_me(msg, to)
@msg = msg
mail to: to, from: @msg.email, subject: @msg.subject, body: @msg.content
end
And when you call contact_me
, you can do: ContactMailer.contact_me(msg, @user.contact_email)
though it may be different depending upon the actual implementation in your code, but the concept would always be same.
这篇关于用户资料的联系表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!