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?}
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---