0

我正在使用带有 simple_form 的 mail_form。我有一个“工作”模型,其中包含一个名为“contact_email”的字符串字段。每个“工作”的contact_email 都不同。我正在尝试有一个发送到该特定电子邮件的表格,但我需要帮助来弄清楚如何去做。

这是我到目前为止所拥有的:

应用程序/routes.rb

resources "contacts", only: [:new, :create]

模型/contact.rb

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

def headers
 {
   :subject => "Contact",
   :to => "email@example.com",
   :from => %("#{name}" <#{email}>)
  }
end

控制器/contacts.rb

def new
 @contact = Contact.new
end

def create
 @contact = Contact.new(params[:contact])
 @contact.request = request
 if @contact.deliver
  flash.now[:notice] = 'Thank you for your message. We will contact you soon!'
 else
  flash.now[:error] = 'Cannot send message.'
  render :new
 end
end

意见/联系人/_new.html.erb

<div align="center">
 <h3>Send A message to Us</h3>
 <%= simple_form_for @contact, :html => {:class => 'form-horizontal' } do |f| %>
  <%= f.input :name, :required => true %>
  <%= f.input :email, :required => true %>
  <%= f.input :message, :as => :text, :required => true %>
  <div class= "hidden">
   <%= f.input :nickname, :hint => 'Leave this field blank!' %>
  </div>
  <div>
  </br>
  <%= f.button :submit, 'Send message', :class=> "btn btn-primary" %>
 </div>
<% end %>

意见/联系人/create.html.erb

<div>
 <% flash.each do |key, value| %>
  <div>
   <a href="#" data-dismiss="alert">×</a>
    <%= value %>
  </div>
<% end %>

意见/工作/show.html.erb

<%= render 'contacts/new' %>

因此,:to => "email@example.com"我不想将电子邮件发送到 job.contact_email (我的作业模型中的字符串)。

4

0 回答 0