简体   繁体   English

Rails视图没有将数据传递给控制器

[英]Rails view isn't passing the data to the controller

So the method from the mailer works. 因此,来自邮件程序的方法有效。 I have tried calling it from the console. 我尝试从控制台调用它。 The issue is that the content variable appears to be empty. 问题是内容变量似乎为空。 So when I call ContactMailer.contact_email from the console [heroku] it works. 因此,当我从控制台[heroku]调用ContactMailer.contact_email时,它将起作用。 I am not sure why =c 我不确定为什么= c

I have also tried doing params[:post][:email] .. to no avail :C 我也试过做params [:post] [:email] ..无济于事:C

controller 控制者

  def contact_email #now how to pass email and content
    email = params[:email]
    content = params[:content]
    ContactMailer.contact_email(email, content).deliver
    redirect_to contact_path, notice: 'Message sent'
  end

view 视图

   <%= form_tag(contact_email_path) do %>
      <div class="form-group">
        <%= label_tag 'email', 'Email' %>
        <%= text_field_tag 'email', nil, class: 'form-control', placeholder: 'Your Email Address' %>
      </div>
      <div class="form-group">
       <%= label_tag 'content', 'Content' %>
         <%= text_area_tag 'content', nil, class: 'form-control', rows: 4, placeholder: 'Content' %>
       </div>
      <%= submit_tag nil, class: 'btn btn-default btn-about pull-right' %>
    <% end %>

route 路线

match '/contact_email', to: 'pages#contact_email', via: 'post'

heroku log heroku日志

2014-04-23T22:25:25.169161+00:00 heroku[router]: at=info method=POST path=/contact_email host=hs-staging.herokuapp.com request_id=6f3753a7-10a0-4354-86b0-81893afefc52 fwd="108.23.126.184" dyno=web.1 connect=4ms service=2276ms status=302 bytes=659
2014-04-23T22:25:25.430981+00:00 heroku[router]: at=info method=GET path=/contact host=hs-staging.herokuapp.com request_id=1c5081eb-eb5d-48eb-9d58-8c699d12f6a3 fwd="108.23.126.184" dyno=web.1 connect=1ms service=45ms status=200 bytes=9356

所以我想heroku需要一个.text.erb电子邮件视图,即使发送到的电子邮件客户端没有使用它也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM