Basically what Pablo says, except that the docs page on rails does not show how to redefine messages for a specific model and field. here is an example from one of my applications:
activerecord: errors: full_messages: format: "{{message}}" #define standard error messages, which we can overide on per model/per attribute basis further down messages: inclusion: "{{attribute}} is not included in the list" exclusion: "{{attribute}} is reserved" invalid: "{{attribute}} is invalid" confirmation: "{{attribute}} doesn't match confirmation" accepted: "{{attribute}} must be accepted" empty: "{{attribute}} can't be empty" blank: "{{attribute}} can't be blank" too_long: "{{attribute}} is too long (maximum is {{count}} characters)" too_short: "{{attribute}} is too short (minimum is {{count}} characters)" wrong_length: "{{attribute}} is the wrong length (should be {{count}} characters)" taken: "{{attribute}} has already been taken" not_a_number: "{{attribute}} is not a number" greater_than: "{{attribute}} must be greater than {{count}}" greater_than_or_equal_to: "{{attribute}} must be greater than or equal to {{count}}" equal_to: "{{attribute}} must be equal to {{count}}" less_than: "{{attribute}} must be less than {{count}}" less_than_or_equal_to: "{{attribute}} must be less than or equal to {{count}}" odd: "{{attribute}} must be odd" even: "{{attribute}} must be even" record_invalid: "Validation failed: {{errors}}" models: quiz: blank: "{{attribute}} can not be blank" user_session: blank: "{{attribute}} can not be blank" attributes: login: invalid: "Please enter your user name" password: invalid: "Please note that passwords are case sensitive"
I also changed the basic format of error messages, because sometimes I did not want the field name to be loaded at the beginning of the message. So I changed
errors: format: "{{attribute}} {{message}}"
to
errors: format: "{{message}}"
That is why I then point out {{attribute}} in my subsequent errors to return it in most, but not all cases.
Note also that I'm using the old syntax {{var}} , not %{var} . However, the same principles apply.
Max williams
source share