Customizing Rails error messages for models and attributes

Updated . Posted . Visible to the public. Repeats.

Rails has generic error messages you can define in your locale .yml files. You may override those application-wide error messages using model or attribute scope like this:

en:
  activerecord:
    errors:
      messages:
        invalid: is invalid # used for any invalid attribute in the application
      models:
        car:
          invalid: does not work # used for invalid car attributes
          attributes:
            driver:
              invalid: not allowed to drive # used if the car's driver attribute is invalid
Dominik Schöler
Last edit
Michael Leimstädtner
Keywords
tailoring
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2013-03-27 14:42)