Skip to content

Commit

Permalink
[Core] Adding a view helper that lists the errors found for a model o…
Browse files Browse the repository at this point in the history
…bject.
  • Loading branch information
Carlos León committed Jul 2, 2011
1 parent e91f3a1 commit fd6c76e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/helpers/application_helper.rb
@@ -1,2 +1,19 @@
module ApplicationHelper

def error_messages_for( object )
result = ''
if object.respond_to? :errors and object.errors.any?
title = "#{ pluralize( object.errors.count, 'error' ) } prohibited this #{ object.class.name.downcase } from being saved:"
result << '<div class="errors_explanation">\n'
result << "<h2>#{ title }</h2>\n"
result << '<ul>\n'
object.errors.full_messages.each do |message|
result << "<li>#{ message }</li>\n"
end
result << '</ul>\n'
result << '</div>\n'
end
result.html_safe
end

end

0 comments on commit fd6c76e

Please sign in to comment.