Rails validates uniqueness while updating object? - very strange -


so, have simple user model, , form updating password.

@user.update_attributes(:password=>params[:password]) 

but didn't work, , figured out:

user load (1.0ms)  select "users".* "users" "users"."auth_token" = 'z7ku4i0ixljirmpdf6sovq' limit 1   user load (0.0ms)  select "users".* "users" "users"."password_reset_token" = 'amojtn0ikpuojo2jmvodtq' limit 1    (0.0ms)  begin   user exists (1.0ms)  select 1 one "users" (lower("users"."email") = lower('somemail@mail.ru') , "users"."id" != 1) limit 1    (0.0ms)  rollback redirected http://localhost:3000/edit_user_by_reset?reset_token=amojtn0ikpuojo2jmvodtq 

by 3rd select can tell, here uniqueness validation failed! , reason rollback. doesn't make sense, of course there such row in db, update action. should do? don't want pass :validate=>false here.

if want update password field only, should not use mass_assignment method update_attributes, should use update_attribute(:password, params[:user][:password]).

there possible error params[:password] hash: if use form_for @user should have params[:user][:password] , in common params[:user] other fields.

you should check if given user valid (did save him db without validation).


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -