gpt4 book ai didi

ruby-on-rails - "Password can' t be blank"播种数据库时出错

转载 作者:行者123 更新时间:2023-12-05 02:22:37 24 4
gpt4 key购买 nike

我正在尝试使用我通过 seed_dump gem found here. 获取的数据为我的数据库做种无论如何,生成的种子文件看起来是合法的,但它似乎与用户模型验证冲突:

ActiveRecord::RecordInvalid: Validation failed: Password can't be blank

给一个想法种子看起来像这样:

User.create!([
{email: "1234@localhost", encrypted_password: "$2a$10$5eoHh6M2q4GjGkHClO.NqebWWhS94D8rNj5Ot6CB2qrbn7IrTfkSa", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2014-12-31 22:27:09", last_sign_in_at: "2014-12-31 22:27:09", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", admin: false}
])

此外,我正在使用 devise gem 进行用户管理。

在给定此过滤器的情况下,是否有一种优雅的方式来播种用户数据?

最佳答案

你可以这样做:

u = User.new([
{email: "1234@localhost", encrypted_password: "$2a$10$5eoHh6M2q4GjGkHClO.NqebWWhS94D8rNj5Ot6CB2qrbn7IrTfkSa", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2014-12-31 22:27:09", last_sign_in_at: "2014-12-31 22:27:09", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", admin: false}
])
u.save!(validate: false)

关于ruby-on-rails - "Password can' t be blank"播种数据库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27931101/

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