Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby ActionMailer的条件默认值_Ruby_Ruby On Rails 4_Actionmailer - Fatal编程技术网

Ruby ActionMailer的条件默认值

Ruby ActionMailer的条件默认值,ruby,ruby-on-rails-4,actionmailer,Ruby,Ruby On Rails 4,Actionmailer,我试图弄清楚逻辑,所以当用户选择下拉选择时,它会使用该电子邮件地址作为默认的发件人地址。例如,如果用户选择store1,它应该从test1@example.com,store2应为test2@example.com等等 这是用户用于选择商店的表单: <%= form_for @entry do |f| %> <div class="form-group"> <%= f.select :store, Store.all.map { |store| [sto

我试图弄清楚逻辑,所以当用户选择下拉选择时,它会使用该电子邮件地址作为默认的发件人地址。例如,如果用户选择store1,它应该从test1@example.com,store2应为test2@example.com等等

这是用户用于选择商店的表单:

<%= form_for @entry do |f| %>
  <div class="form-group">
    <%= f.select :store, Store.all.map { |store| [store.name]  }, :selected => @entry.store %>
  </div>
<% end %>
在stores表中,我有列name和email_address。

您将无法使用默认设置来完成此操作-默认设置适用于您不想自定义电子邮件的情况

在编写传递方法时,接受entry或store作为参数,并在运行时使用它从地址中选取。看起来像

class ApplicationMailer < ActionMailer::Base
  layout 'mailer'

  def entry_email(entry)
    mail(from: entry.store.email_address)
  end
end
class ApplicationMailer < ActionMailer::Base
  layout 'mailer'

  def entry_email(entry)
    mail(from: entry.store.email_address)
  end
end
ApplicationMailer.entry_email(entry).deliver