Hello all
i have a registration form. i am validating say, password field using
validates_presence_of :password, :if => :password_required?
validates_presence_of :password_confirmation, :if
=> :password_required?
validates_length_of :password, :within => 4…40, :if
=> :password_required?
validates_confirmation_of :password, :if => :password_required?
now in my form while submitting, if i wont put password i got 4 error
messages:
password is required
password length should be min 4 chars. and so on
my question is, Is there a way to customize these error messages? all
i need is just one error message per field.
any suggestion?
thanks in advance.
Ajit
Ajit Singh wrote:
Hello all
i have a registration form. i am validating say, password field using
validates_presence_of :password, :if => :password_required?
validates_presence_of :password_confirmation, :if
=> :password_required?
validates_length_of :password, :within => 4…40, :if
=> :password_required?
validates_confirmation_of :password, :if => :password_required?
now in my form while submitting, if i wont put password i got 4 error
messages:
password is required
password length should be min 4 chars. and so on
my question is, Is there a way to customize these error messages? all
i need is just one error message per field.
any suggestion?
thanks in advance.
Ajit
You should use the :unless option of the validates method in
“validates_length_of :password”. This option specifies a method to call
to determine if the validation should not occur.
validates_length_of :password, :unless => Proc.new{|o|
o.password.blank?}