Rails アプリで連絡先を処理するために gem mail_form を使用しています。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
クロムでhtmlを出力します:
<input type="hidden" name="mail_subject" id="mail_subject" value="Where to buy">