Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I just went through my own issues with this. The following code should work as advertised (as found on the wiki page for Devise).</p> <pre><code>def update @user = User.find(current_user.id) successfully_updated = if needs_password?(@user, params) @user.update_with_password(params[:user]) else params[:user].delete(:current_password) @user.update_without_password(params[:user]) end if successfully_updated set_flash_message :notice, :updated sign_in @user, :bypass =&gt; true redirect_to after_update_path_for(@user) else render "edit" end end </code></pre> <p>Make sure you also define the private method for 'needs_password?'</p> <pre><code>def needs_password?(user, params) (params[:user].has_key?(:email) &amp;&amp; user.email != params[:user][:email]) || !params[:user][:password].blank? end </code></pre> <p>My issue was that I had removed the "email" field from the form in the 'edit.html.erb' file, so the 'needs_password?' method kept returning true since user.email was never equal to nil. To fix the issue, I added in a check <code>params[:user].has_key?(:email)</code> to see if 'email' exists in the hash.</p> <p>FWIW, the 'update_without_password' pretty much works the same way as 'update_with_password' except that it strips out the 'password' and 'password_confirmation' parameters before calling 'update_attributes' on the object, so you shouldn't have to do anything more. Try looking upstream a bit and see if you really are calling 'update_without_password'.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload