Rails 3.2 create a form that's used in the footer of every page

前端 未结 2 664
时光说笑
时光说笑 2021-01-17 03:44

I want to create a form that\'s used to sign up to a mailing list in the footer of my webpage. What I did was create a partial that renders this small form in the footer of

2条回答
  •  没有蜡笔的小新
    2021-01-17 04:17

    You can change your form_for method to this:

    <%= form_for :mailing_list, url: mailing_lists_path do |f| %>
    

    Then you no longer need to initialize @mailing_list for every page.

    The caveat is that you cannot render the errors in the footer. You would need to create a new.html.erb view using the code in the question, that can be rendered if there are any errors when saving in the create action.

提交回复
热议问题