Making pretty error messages is easy. And fun! I overwrote error_messages_for because I wanted to include multiple objects in the error message list. Then I freaked out and loaded it up with lotsa functionality.
- Print error messages for multiple objects by listing them in an array. Objects can be specified:
- The object. (
@userornon_instance_object) - Specify objects as a string representing the name of an instance variable (
'email_address'to refer to@email_address)
- The object. (
<%= error_messages_for [@user, 'email_address', non_instance_object] %>
<%= error_messages_for 'non_instance_object' %>
- Customize the header message or the sub header message
<%= error_messages_for 'user', :header_message=>'%d errors prohibited you from creating a happy pony party.', :header_sub_message=> 'these ponies were bad:' -%>
- Skip or customize the field name display. Perhaps in one context you call it “Primary email address” and in another, you refer to it as “Contact Information”. Or you just dont want to report errors on the field.
<%= error_messages_for 'user', :sub=>{'email_address_text'=>'Primary Email Address'}, :skip=>['credit_card_number'] -%>
- Compatible with the awesome globalize plugin. (If you don’t like global things, then you should remove the .t business.
Codeage:
Read the rest of this entry »
Posted by blythedunham
Posted by Chris Hobbs