如何在设计 3.2.x 中手动更改/更新用户密码? [英] How do I manually change/update a user password in devise 3.2.x?
问题描述
我试图从我的 seeds.rb
中做到这一点:
I tried to do this from my seeds.rb
:
user = User.find_or_create_by email: ENV['ADMIN_EMAIL'].dup, password: ENV['ADMIN_PASSWORD'].dup, password_confirmation: ENV['ADMIN_PASSWORD'].dup
我收到此错误消息:
PG::UndefinedColumn: ERROR: column users.password does not exist
LINE 1: ...sers" WHERE "users"."email" = 'abc@test.com' AND "users"."p...
我尝试了 encrypted_password
,但是对于 users.encrypted_password_confirmation
不存在,我得到了相同的结果.
I tried encrypted_password
, but then I get the same for users.encrypted_password_confirmation
does not exist.
关于最好的方法的想法?
Thoughts on the best way to do this?
推荐答案
我只想进入 Rails 控制台 (rails c
)
I would just go into the Rails console (rails c
)
user = User.new(email: "myemail.com", password: "superSecret")
user.save
你也可以改变它
user = User.find_by_email("myemail.com")
user.password = "newSuperSecret"
user.save
我只是把我的第一个代码块放在我的 seed.rb
中,然后运行 rake db:seed
没有问题.所以我认为您的问题的症结在于您的 find_or_create_by
调用中的密码属性.我想如果你把它放在你的 seed.rb
中,你会得到你想要的结果(虽然我不得不承认我不确定环境变量的工作,你可能需要重新调整那个部分的).
I just put my first block of code in my seed.rb
and ran rake db:seed
with no problem. So I think the crux of your problem is just having the password attribute in your find_or_create_by
call. I think if you put this in your seed.rb
you'll get the results you want (although I have to admit I'm not certain about the environment variables working, you might have to retool that portion of it).
user = User.find_or_create_by(email: ENV['ADMIN_EMAIL'].dup)
user.password = ENV['ADMIN_PASSWORD'].dup if user.encrypted_password.blank?
user.save!
这篇关于如何在设计 3.2.x 中手动更改/更新用户密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!