私は完全に混乱しています。私はRails 4を学習していますが、これは期待どおりにユーザーレコードを返します:
irb(main):002:0> User.all
しかし、これは戻りますnil
irb(main):004:0> User.authenticate('asdfdsf', 'asdfdas')
モデルのクラス メソッドは次のとおりです。
def self.authenticate( email, password )
user = User.all #( email: email )
puts user
# if user && (user.hashed_password == User.hash_with_salt( password, user.salt ) )
# return user
# else
# return false
# end
end
何か不足していますか?これらは両方とも同じものを返すべきではありませんか? クラス メソッド内から .find() または .where() を使用してユーザー オブジェクトを返せないのはなぜですか?
更新: ユーザー テーブルのスキーマは次のとおりです。
create_table "users", force: true do |t|
t.string "first_name"
t.string "last_name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "hashed_password"
t.string "salt"
end