Skip to content

Instantly share code, notes, and snippets.

@williamromero
Created November 2, 2017 17:24
Show Gist options
  • Save williamromero/b5d1e74915210e108c81935e29968e7a to your computer and use it in GitHub Desktop.
Save williamromero/b5d1e74915210e108c81935e29968e7a to your computer and use it in GitHub Desktop.
Updating users in Devise without fuck up your current user data
def update
  respond_to do |format|
    # information. Devise solution: https://github.com/plataformatec/devise/wiki/How-To:-Manage-users-through-a-CRUD-interface
    if params[:user][:password].blank?
      params[:user].delete(:password)
      params[:user].delete(:password_confirmation)
    end        
    if @user.update_attributes(user_params)  
      format.html { redirect_to dashboard_path, notice: 'The user role was updated' }
    else
      format.html { render :edit }
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment