gpt4 book ai didi

ruby-on-rails - 带有 BCrypt 的 Rails Fixtures

转载 作者:行者123 更新时间:2023-12-04 05:43:27 25 4
gpt4 key购买 nike

我遇到了 BCrypt 密码固定装置的问题:
我的 User模型都设置为 has_secure_passwordvalidates_presence_of :password .

关键是 BCrypt 使用 passwordpassword_confirmation但在模式中只有 password_digest field 。

夹具提示 password字段不存在。

我怎样才能避免这种情况?

谢谢

最佳答案

似乎夹具被直接推送到数据库。这意味着,而不是 password:您需要password_digest:在你的固定装置中:

test_user:
email: "tester@testing.net"
password_digest: <%= BCrypt::Password.create('testpassword', cost: 5) %>
has_secure_password 使用基于 bcrypt 的密码时.正如评论中提到的 cost参数是可选的。如果您不使用它,将使用合理的默认值。
更新:在 Rails 6 中 bcrypt 默认不可用,需要明确添加/要求

关于ruby-on-rails - 带有 BCrypt 的 Rails Fixtures,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30894771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com