Custom Column Names for ActiveRecord Validation Messages

If you need to customize the field name for ActiveRecord validation messages, I wrote this quick little include that allows you to remap column names.

For example, if you have a User with a name field and you didn't like the default "Name cannot be blank." message, and instead wanted "Your name cannot be blank" you can include this module and use rename_fields :name => 'Your Name' to rename the column.

The easy way to do this is to overwrite your class's human_attribute_name method (see documentation for more info). This is how ActiveRecord looks up your column names.

Since this is kind of a pain to do for every class, and maintain separate column maps, I wrote this quick-and-dirty module that you can include in your class and call rename_fields.