Created
April 10, 2009 15:03
-
-
Save olkeene/93121 to your computer and use it in GitHub Desktop.
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
module ActiveRecord | |
class Errors | |
# Redefine the ActiveRecord::Errors::full_messages method: | |
# E.g. validates_acceptance_of :accepted_terms, :message => 'Please accept the terms of service' | |
def full_messages | |
full_messages = [] | |
@errors.each_key do |attr| | |
@errors[attr].each do |msg| | |
full_messages << msg unless msg.nil? | |
end | |
end | |
return full_messages | |
end | |
end | |
end | |
module ApplicationHelper | |
def validation_errors(object, summary = nil) | |
return if object.nil? || object.errors.empty? | |
content_tag(:div) do | |
html = content_tag(:h4, summary || 'The form was filled with the errors', :class => 'errors') | |
html << content_tag(:ul) do | |
object.errors.full_messages.map { |msg| content_tag(:li, msg) }.join() | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment