Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise password reset from Rails console

While running an app how do you select a user by email address and then set the password manually within rails console for Devise?

Also, where would I go to review documentation to cover more details in this regard to manipulation of accounts while using Devise?

like image 207
ylluminate Avatar asked Nov 29 '11 05:11

ylluminate


4 Answers

Modern devise allows simpler syntax, no need to set the confirmation field

user.password = new_password; user.save
# or
user.update(password: new_password)
like image 79
Sergio Tulentsev Avatar answered Nov 09 '22 19:11

Sergio Tulentsev


# $ rails console production
u=User.where(:email => '[email protected]').first
u.password='userpassword'
u.password_confirmation='userpassword'
u.save!
like image 25
Eric Guo Avatar answered Nov 09 '22 19:11

Eric Guo


If you run the following in the rails console it should do the trick:

User.find_by(email: 'user_email_address').reset_password!('new_password','new_password')

http://www.rubydoc.info/github/plataformatec/devise/Devise/Models/Recoverable

like image 30
gstraehle Avatar answered Nov 09 '22 18:11

gstraehle


You can simply update password field, no need for confirmation password, devise will save it in encrypted form

u = User.find_by_email('[email protected]')
u.update_attribute(:password, '123123')
like image 6
Kshitij Avatar answered Nov 09 '22 17:11

Kshitij