加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Authlogic current_user_session和current_use

发布时间:2020-12-17 02:17:35 所属栏目:百科 来源:网络整理
导读:我在application_controller.rb中为authlogic提供了以下帮助方法: def current_user_session return @current_user_session if defined?(@current_user_session) @current_user_session = UserSession.findenddef current_user return @current_user if def
我在application_controller.rb中为authlogic提供了以下帮助方法:

def current_user_session
  return @current_user_session if defined?(@current_user_session)
  @current_user_session = UserSession.find
end

def current_user
  return @current_user if defined?(@current_user)
  @current_user = current_user_session && current_user_session.record
end

我不明白current_user_session方法如何 – 具体来说,UserSession.find如何获取当前用户的会话.我也不明白它在使用find时做了什么,没有给出任何参数.

解决方法

它不需要传递参数,因为它使用的是功能为 built into Rails的 unique session ID.有关它的更多信息,请查看 authlogic documentation for the find method.它与Active Record类不同,它在find中查询数据库中的特定主键.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读