Customizing error messages on ActiveRecord

Hi Everyone,

Is there a gem plugins that can customize the built-in error messages
that we are seeing when there’s an error an ActiveRecord?

I am referring on this message

“7 errors prohibited this RECORD from being saved”

Haven’t seen a plugin like that. Though you could rather easily create
your own partial to do this by accessing the errors directly through

@record.errors

Personally, I have always favored designs that make use of the
“error_message_on” helper

Ok… After a few ‘google’ session, I finally found this solution and I
hope it will helps you out there.

Insert this block of code on your application_helper.rb (found on
app/helper)


def error_messages_for(object_name, options = {})
options = options.symbolize_keys
object = instance_eval “@#{object_name}”
unless object.errors.empty?
content_tag(“div”,
content_tag(options[:header_tag] || “h2”, “WARNING:”) +
content_tag(“ul”, object.errors.full_messages.collect { |msg|
content_tag(“li”, msg) }),
“id” => options[:id] || “errorExplanation”, “class” =>
options[:class] || “errorExplanation”
)
end
end #def error_messages_for


Thats it… !!! a customized error message header for your ActiveRecord
error message box. :wink: