0

我遵循了本指南https://rubyonrailshelp.wordpress.com/2014/01/08/rails-4-simple-form-and-mail-form-to-make-contact-form/

在联系表单中,用户填写他们的姓名和电子邮件以及消息的字段。

class ContactForm < MailForm::Base

  attribute :name,      :validate => true
  attribute :email,     :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
  attribute :message
  attribute :nickname,  :captcha  => true

  # Declare the e-mail headers. It accepts anything the mail method
  # in ActionMailer accepts.
  def headers
    {
      :subject => "My Contact Form",
      :to => "FILLTHISIN@example.com",
      :from => %("#{name}" <#{email}>)
    }
  end
end

我想从user.email属性自动发送,而不是让用户填写字段。这可能吗?

4

1 回答 1

1

这个:

在你的,app/views/contacts/new.html.erbmake email fieldashidden field和 use current_user.emailas valueofhidden email field应该可以工作。

注意:我假设您正在使用Devisegem

于 2016-08-12T13:55:57.840 回答