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 the application layout.
Here is the code for the partial:
<%= form_for(@mailing_list) do |f| %>
<% if @mailing_list.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@mailing_list.errors.count, "error") %> prohibited this mailing_list from being saved:</h2>
<ul>
<% @mailing_list.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :first_name %><br />
<%= f.text_field :first_name %>
</div>
<div class="field">
<%= f.label :last_name %><br />
<%= f.text_field :last_name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
I'm still learning rails so that's generated code from scaffolding. From what I gather I need to instantiate the @mailing_list variable with @mailing_list = MailingList.new but the problem here is that NEW action in the mailing list controller doesn't get called because I'm not necessarily visiting that page. This form is in the footer of every page.
What would be the proper way to create this form? Is there a way to do this without calling MailingList.new in every controller?
Thanks!