How do I find user by username rather than email in ruby on rails 3.1?
I've tried a few things but can't seem to get my head round it. I've been practicing and know how to do this using email but how can I do it using username?
def self.authenticate(username, password)
user = find_by_name(username)
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.pa开发者_如何学Pythonssword_salt)
user
else
nil
end
end
Change
user = find_by_name(username)
to
user = find_by_username(username)
精彩评论