开发者

The Authlogic record method. What does this do

I came across this meth开发者_如何学Pythonod 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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜