Skip to content

Instantly share code, notes, and snippets.

@HammerInTheNews
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HammerInTheNews/350cb97b7e2221a734de to your computer and use it in GitHub Desktop.
Save HammerInTheNews/350cb97b7e2221a734de to your computer and use it in GitHub Desktop.
Add error message handling
# Put this in the form_for loop after "do"
<%= render 'shared/errors', object: @object_name %>
# Then in the shared/errors partial put:
<% if object.errors.any? %>
<section id="errors">
<header>
<h2>
Oops! The <%= object.titleize.downcase %> could not be saved.
</h2>
<h3>
Please correct the following <%= pluralize(object, "error") %>:
</h3>
</header>
<ul>
<% object.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</section>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment