Skip to content

Instantly share code, notes, and snippets.

@oelmekki
Created May 23, 2013 12:19
Show Gist options
  • Save oelmekki/5635663 to your computer and use it in GitHub Desktop.
Save oelmekki/5635663 to your computer and use it in GitHub Desktop.
module ApplicationHelper
# Format errors for display.
# Resource may be a model or an handler - just anything including ActiveModel::Validations
#
# @param [Object] resource the source of errors
# @return [String] the error html
def error_messages_for_handler( resource )
message = <<-EOS
<div id="error_explanation">
<ul>
%s
</ul>
</div>
EOS
lines = resource.errors.full_messages.map { |msg| '<li>%s</li>' % msg }.join( "\n" )
( message % lines ).html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment