I have a user model in which there is an authentication method.
If I test using the model in the rails console, you can create a user just fine, and then I can find an email on it and return the user in the same way.
user = User.find_by_email("someaddress@email.com")
Now, if I try to call an authentication method like this and return the user, the puts operator in my authentication method returns nil
user = User.authenticate("someaddress@email.com", "foobar")
The model looks something like this:
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :first_name, :last_name,
:email, :birth_date, :sex,
:password, :password_confirmation
def self.authenticate(email, submitted_password)
user = find_by_email(email)
puts user
return nil if user.nil?
return user if user.has_password?(submitted_password)
end
end
I do not understand what the problem is. Some of them see in this question.
source
share