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”
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”
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs