2017-05-14 28 views
2

deviseユーザモデルでdevise-two-factor gemを使用しています。私はモデルから宝石を削除しようとするユーザーレコードを作成するときに、私は次のエラーを取得する:Rails、Devise:不明な属性 'password' for user

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! 

どのようにこれらの2行は、モデルのpassword属性に影響を与え削除しますか?そのコードスニペットは私が変更した唯一のものです。

+2

あなたは質問に、あなたの 'デシベル/ seeds.rb'ファイルを追加することはできますか? – ArtOfCode

+0

@ArtOfCodeマークアップに追加しました – jonhue

答えて

1

two_factor_authenticatable説明:あなたのモデルの形式が:authenticatableの場合、Deviseはパスワードでのみ動作します。 代わりに:database_authenticatableを追加すると、Deviseはパスワードを正しく割り当てることができます。

それは、より多くのための工夫のマニュアルを参照してください、助けていない場合は、次のhttps://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview#using-omniauth-without-other-authentications

2
demo_user = User.create(email: '[email protected]', first_name: 'demo', 
         last_name: 'account', password: '12345678', 
         username: 'demo') 

問題があります。 Userpasswordアトリビュートを設定しようとしていますが、Devise Userモデルにはpasswordアトリビュートがありません。

Deviseユーザーはencrypted_password属性を持っていますが、ユーザーが作成されたときにDeviseによって生成され、おそらく自分で埋めてはいけません。これは、password属性を暗号化する方法ではありません。

+0

私の開発者がデフォルトの 'password'入力でフォームにサインアップしても失敗するので、これは意図していないと思います。 – jonhue

+0

なぜ 'password'が' two-factor'に依存するのか、私はまだ分かりません。宝石ですべてがうまく動作します。 – jonhue

+0

'User.create(電子メール: '...'、パスワード: '12341234'、password_confirmation: '12341234')'は、暗号化されたパスワードをDeviseに保存します。 – speedracr

関連する問題