Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Authlogic record method. What does this do

I came across this method called record that Ryan bates uses in his authlogic Railscast and can't seem to understand what it does. I have been through the documentation but I can't seem to follow how that helper is useful.

def current_user
  return @current_user if defined?(@current_user)

  current_user_session && current_user_session.record
end

What I want to know is does this simply fetch the record from the database and why is it different from the standard way of fetching data from the database.

Thank you.

like image 556
Sid Avatar asked Oct 12 '09 08:10

Sid


1 Answers

This "record" method is a belongs_to relation between the UserSession and the User models. So based on the Session, it returns the User.

However based on the documentation, it's not "record" anymore. But "user". So your current_user helper method should be the following :

def current_user
    return @current_user if defined?(@current_user)
    @current_user = current_user_session && current_user_session.user
end
like image 109
Damien MATHIEU Avatar answered Oct 14 '22 09:10

Damien MATHIEU