views:

230

answers:

1

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.

+4  A: 

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
Damien MATHIEU
Thank you very much. That was really helpful.Cheers
Sid