2016-04-17 43 views
2

ユーザーモデルのメールフィールドはattr_encryptedで暗号化されています。 deviseとfacebook omniauthで新しいユーザーを作成すると、実際にDBに保存されます。また、そのデータをUser.last.email #=> [email protected]で取得できます。'find_by'と 'where'はattr_encryptedと連携していません

User.find_by_email("[email protected]")またはUser.where(email: "[email protected]")を使用すると、nilまたは[]が返されます。

user.rb

class User < ActiveRecord::Base 
    attr_encrypted :email, key: Settings.encryption.key 
end 

答えて

1

あなたがattr_encrypted宝石を使用している場合は、私がemailが仮想フィールドであり、実際にencrypted_emailフィールドとしてusersテーブルに保存されていると思います。

schema.rbファイルはusersテーブルでどのように見えますか?

このような場合は、私はあなただけではなく、

User.find_by_email("[email protected]") 

宝石のドキュメントの

User.find_by_encrypted_email("[email protected]") 

を使用する必要があると思う:https://github.com/attr-encrypted/attr_encrypted

幸運!

関連する問題