【发布时间】:2015-07-25 20:21:19
【问题描述】:
我正在使用 gem mail_form 来处理 Rails 应用程序中的联系,我有 6 种不同的联系表单。
我在表单中放置了一个 hidden_field_tag 并将所需的主题作为变量传递。在 html 中,该值存在,但 电子邮件到达时带有(无主题)。我做错了什么?
在控制器中
def where_to_buy
@contact = Contact.new
@the_subject = "Where to buy"
end
联系方式
= form_for @contact do |f|
= render "form", f: f
= f.text_area :message
.hide
= f.text_field :nickname, hint: 'Leave this field empty!'
= hidden_field_tag :mail_subject, @the_subject
= f.submit "Send Message"
在模型中
class Contact < MailForm::Base
attribute :mail_subject
attribute :first_name, validate: true
attribute :last_name, validate: true
attribute :message, validate: true
attribute :nickname, captcha: true
def headers
{
subject: %(#{mail_subject}),
to: "jorge@email123.com",
from: %("#{first_name} #{last_name}" <#{email}>)
}
end
end
在chrome中输出html:
<input type="hidden" name="mail_subject" id="mail_subject" value="Where to buy">
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 mail-form