I want to write a custom error message for :minimum and other for :maximum
I have the following the code line
validates_length_of :user_name, :minimum=>5,:maximum=>30
ej if the length of :user_name is < 5 "The user_name must to have 5 characters as minimum"
ej if the length of :user_name is > 30 "The user_name must to have 30 characters as maximum"
The newer notation for this is:
validates :user_name,
length: {
minimum: 5,
maximum: 30,
too_short: "The user name must have at least %{count} characters.",
too_long: "The user name must have no more than %{count} characters."
}
More examples are listed in the documentation.
The old validates_length_of
type methods are left in there for legacy support but should probably be avoided in new code.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments