Build custom error messages in model files (example: using the 'pluralize' method)
- by user502052
I am using Ruby on Rails 3.0.7 and I would like to use the pluralize method in a my model file in order to properly build custom error messages.
For example, I would like to do something like the following:
NAME_MIN_LENGHT = 2 # Is 2 but I plan to change that (maybe dynamically... if it is possible) in future development
validates :name,
:length => {
:minimum => NAME_MIN_LENGHT,
:too_short => "is too short (minimum is #{pluralize(NAME_MIN_LENGHT, "character")})",
},
How can I do that? Is it advisable? Why?