My User model contains :name, :email, and :password fields. All 3 have validations for length. An “update account” web page allows the user to update his name and email address, but not password. When submitted, params[:user] is
{"name"=>"Joe User", "email"=>"user@example.com"}
Note there is no “password” key because the form doesn’t contain such an input field.
When I call
@user.update_attributes(params[:user])
the password validation fails. However, since I’m not attempting to update the password, I don’t want the password validation to run on this update. I’m confused why the password validation is running when params[:user] doesn’t contain a “password” key.
Note that I want to have a separate web page elsewhere that allows the user to update his password. And for that submission, the password validation should run.
Thank you.
My application does something like this
so you have to
model.updating_password = truefor the verification to take place, and you don’t have to do this on creation.Which I found at a good railscast at http://railscasts.com/episodes/41-conditional-validations