RailsCasts Pro episodes are now free!

Learn more or hide this

Juan Pujol's Profile

GitHub User: juanpujol

Site: juanpujol.com

Comments by Juan Pujol

Avatar

This validation subject is getting complex...

Let's say I validate like this:

ruby
 validates :password, :password_confirmation, :presence => true

and I use the tip above:

ruby
save!(validate: false)

This works perfectly. But If I don't want the user to confirm the password every time he saves the profile I would do like this.

ruby
validates :password, :password_confirmation, :presence => true, :if => :password

This works too. Even validates on the reset password form and ask for confirmation if the password changes on the profile. But, it has a problem. if I submit the reset password form without any value for the password or password_confirmation it won't validate the presence of :password or :password_confirmation. The password won't be updated but it'll be nice to show the validation errors for presence in this scenario.

I don't know if any one has this issue, but I would appreciate some light here.

Thanks