该Authlogic记录方法。这是什么呢 [英] The Authlogic record method. What does this do

查看:116
本文介绍了该Authlogic记录方法。这是什么呢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到这个方法叫做记录,瑞安贝茨使用他的authlogic Railscast和似乎无法了解它。我经历过的文档,但我似乎无法遵循怎样的帮助是非常有用的。

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.

感谢你。

推荐答案

这个记录的方法是UserSession和用户模型之间的belongs_to的关系。 因此,基于会话,它会返回给用户。

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

然而基础上,文档,这不是记录了。但用户。 所以,你的CURRENT_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

这篇关于该Authlogic记录方法。这是什么呢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆