Skip to content

Instantly share code, notes, and snippets.

@natebird
Created November 13, 2010 19:55
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 natebird/675585 to your computer and use it in GitHub Desktop.
Save natebird/675585 to your computer and use it in GitHub Desktop.
Application helper to simplify the views in Rails3
# app/helpers/application_helper.rb
def form_errors(form)
if form.errors.any?
content_tag :h2, "#{pluralize(form.errors.count, 'error')} prohibited this #{form.class} from being saved:"
content_tag :ul
form.errors.full_messages.each do |msg|
content_tag :li, msg
end
end
end
# View
= form_errors(@idea)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment