从Rails控制台设计密码重置 [英] Devise password reset from Rails console

查看:96
本文介绍了从Rails控制台设计密码重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行应用程序时,如何通过电子邮件地址选择用户,然后在 rails控制台中为Devise手动设置密码?

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

此外,在使用Devise时,我在哪里可以查看文档以涵盖有关帐户操作的更多详细信息?

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

推荐答案

与您描述的差不多:-)

It's more or less as you described :-)

# use mongoid
class User
  include Mongoid::Document
end


# then
user = User.where(email: 'joe@example.com').first

if user
  user.password = new_password
  user.password_confirmation = new_password
  user.save
end



从6年后开始更新:)



现代设计允许使用更简单的语法,无需设置确认字段

Update from 6 years later :)

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

user.password = new_password; user.save
# or
user.update_attributes(password: new_password)

这篇关于从Rails控制台设计密码重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆