Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core] Adding a view helper that lists the errors found for a model o…
…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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |