How can I customize the error messages for sub options when validating numericality on a field in an ActiveRecord model?
Example:
validates :month, :numericality => {
:greater_than_or_equal_to => 1,
:less_than_or_equal_to => 12
}
In this case if the ‘month’ attribute is more than 12, I want to provide custom error message instead of the default “must be less than or equal to 12”. How to achieve this?
If you don’t want to use a custom validator, you could use the
en.ymlfile instead. Assuming “post” was your model name, this provides examples for age-specific messages, post-specific messages, and generic (all models) messages.