title: Rails API - Devise: Update password on User update
body: <p>I'm having a very weird issue with devise when trying to edit a user's password - here is a simplified version of what I'm doing at the moment:</p>
  
  <pre><code>def update
  
    user = User.find(params[:id])
    password              = params.delete(:password)
    password_confirmation = params.delete(:password_confirmation) 
  
    if password.present? and password != "" and password == password_confirmation
      user.password = password
    end
  
    user.update(params)
    user.save
  
    render json: user
  end
  </code></pre>
  
  <p>What's really weird is that if I set password to an arbitrary string, by putting </p>
  
  <pre><code> password = "testpassword"
  </code></pre>
  
  <p>above</p>
  
  <pre><code> user.password = password
  </code></pre>
  
  <p>it works properly, the password is set to "testpassword", and i can log in using it just fine. But if I try and use the param like in the code above, I cannot log in using the password set in params[:password]. I have tried forcing the encoding of the string, and to use user.update_without_password, but to no avail.</p>
  
  <p>Would anybody have any idea about this? it's driving me bonkers!</p>
  
  <p>here is a dump of the params hash:</p>
  
  <pre><code> {"username"=&gt;"testytest", 
    "first_name"=&gt;"Test",
    "last_name"=&gt;"testy",
    "password"=&gt;"password", 
    "password_confirmation"=&gt;"password"}
  </code></pre>
  
  <p>To be a bit more precise, trying to login once this has been fired results in me not being able to login using the old password, or the new one. if there was a way to see which password gets saved in that function, I should be able to debug it!</p>