Skip to content

Instantly share code, notes, and snippets.

@olkeene
Created April 10, 2009 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olkeene/93121 to your computer and use it in GitHub Desktop.
Save olkeene/93121 to your computer and use it in GitHub Desktop.
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