Rails:为什么在用户提交表单之前发送电子邮件?

时间:2016-12-04 15:24:01

标签: ruby-on-rails forms email controller routes

我有一个"静态表格"如果要向客户发送价格表,我需要发送一封电子邮件,但表格中的params [:pricelist_name]为零。

我注意到电子邮件是在视图之前发送的,所以我想知道如何在用户提交表单后才发送电子邮件?

干杯,

控制器

ui-sref

查看

  def sendpricelist
    @pricelist = params[:pricelist_name] || []
    @request_id = params["pricelist_name"] || []
    @test = "test"
    SaasMailer.pricelist_request_email(@pricelist, @test, @request_id).deliver_now
    #redirect_to :requests
end

路线

    <%= form_tag(:controller => "requests", :action => "sendpricelist") do %>
  <%= text_field(:post, :title, size: 69, class: 'form-control form-group-lg') %>


<%= select_tag 'pricelist_name', 
  options_from_collection_for_select(Pricelist.all, :id, :name) %>


    <%= submit_tag("Send pricelist")%>



<% end %>

输出:

正如您在&#39;主题中所看到的:[] - [] - 测试&#39;参数是零。

 devise_for :users
 resources :users
 resources :requests do
 resources :updates
match '/sendpricelist',      to: 'requests#sendpricelist',           via: 'get'

end

1 个答案:

答案 0 :(得分:0)

我将路线更改为match '/sendpricelist', to: 'requests#sendpricelist', : via =&gt; [:get,:post]`