有没有人知道为什么在使用has_secure_password的简单模型上创建失败?
我有rails 4.0.2 我有一个非常简单的模型: $ rails g资源提供者名称password_digest
with models / provider.rb
class Provider < ActiveRecord::Base
has_secure_password
end
使用rails控制台我正在尝试创建一个模型:
2.0.0-p353 :013 > Provider.create(name: "boot", password: "Boot1234tooB")
(0.1ms) begin transaction
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
(0.1ms) rollback transaction
=> #<Provider id: nil, name: "boot", password_digest: "$2a$10$yOkRGwFioJVhZTwiEKTQseGsHM9vQ82UAPAkkF4FGUwX...", created_at: nil, updated_at: nil>
2.0.0-p353 :014 > print Provider.all.to_yaml
Provider Load (4.7ms) SELECT "providers".* FROM "providers"
--- []
=> nil
由于 罗布
答案 0 :(得分:2)
您应该设置password_confirmation
:
Provider.create(name: "boot", password: "Boot1234tooB", password_confirmation: "Boot1234tooB")
的更多信息