Created
July 29, 2011 13:44
-
-
Save mattyoho/1113828 to your computer and use it in GitHub Desktop.
Rails 3 #error_messages_for, via @j3 => @RyanBates
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
def error_messages_for(*objects) | |
options = objects.extract_options! | |
options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields") | |
options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.") | |
messages = objects.compact.map { |o| o.errors.full_messages }.flatten | |
unless messages.empty? | |
content_tag(:div, :class => "error_messages") do | |
list_items = messages.map { |msg| content_tag(:li, msg) } | |
content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where error_messages_for.rb does reside in a project?