Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise update user without password

I want to update users attributes without password in devise. The case is like, if password and password confirmation fields are not blank then I need devise error and if they are blank then other user attributes need to be updated. How could I do this with devise?

Thanks in advance!

like image 642
kriysna Avatar asked Feb 25 '11 03:02

kriysna


1 Answers

I think this is a much better solution:

if params[:user][:password].blank? && params[:user][:password_confirmation].blank?     params[:user].delete(:password)     params[:user].delete(:password_confirmation) end 

This prevents you from having to change the Devise controller by simply removing the password field from the form response if it is blank.

Just be sure to use this before @user.attributes = params[:user] or whatever you use in your update action to set the new parameters from the form.

like image 173
John Avatar answered Oct 24 '22 05:10

John