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
change your form to this
<%= form_for MailingList.new, html: { remote: true } do |f| %>
so you don't have to worry about instance variables. You should also pass remote: true
so the form is submitted via ajax. To show error, create a file called create.js.erb
under app/views/mailing_lists
and add the following (just a simple script that appends the errors before the form)
$('.error-messages').remove();
<% if @mailist_list.errors.any? %>
$('#new_mailing_list').before('- <%= escape_javascript msg %>
');
<% end %>
<% end %>
');
<%= @mailing_list.errors.full_messages.each do |msg| %>
$('.error-messages').append('