Rails,Devise:用户的未知属性'密码'
问题描述:
我一直在使用我的devise用户模型上的devise-two-factor宝石。当我尝试从模型中移除宝石,我创建一个用户记录时收到以下错误:Rails,Devise:用户的未知属性'密码'
ActiveModel::UnknownAttributeError: unknown attribute 'password' for User. c:/test_app/db/seeds.rb:6:in
<top (required)>' bin/rails:4:in
require' bin/rails:4:in `'
这里是我以前的色器件集成在我的模型:
devise :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable,
:omniauthable,
:invitable,
:two_factor_authenticatable, :two_factor_backupable,
:otp_secret_encryption_key => Settings.devise.two_factor.key,
:omniauth_providers => [:google_oauth2]
而且我目前的积分:
devise :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable,
:omniauthable,
:invitable,
:omniauth_providers => [:google_oauth2]
我的种子:
demo_user = User.create(email: '[email protected]', first_name: 'demo', last_name: 'account', password: '12345678', username: 'demo')
demo_user.encrypted_password
demo_user.skip_confirmation!
如何删除这两条线影响模型的password
属性?该代码片段是我改变的唯一的东西。
答
two_factor_authenticatable
是解释:设计只能使用密码,如果您的模型有某种形式:authenticatable
。 尝试添加:database_authenticatable
,而Devise应该能够正确地分配密码。
如果没有帮助,请参阅更多的设计文档:https://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview#using-omniauth-without-other-authentications
答
demo_user = User.create(email: '[email protected]', first_name: 'demo', last_name: 'account', password: '12345678', username: 'demo')
这是您的问题。您正尝试在新的User
上设置password
属性,但设计User
型号没有password
属性。
设计用户拥有encrypted_password
属性,但是在创建用户时由Devise生成,您可能不应该尝试自行填充它。这不是一种加密password
属性的方法。
您可以将您的'DB/seeds.rb'文件的问题? – ArtOfCode
@ArtOfCode我将它添加到标记 – jonhue