7

我想知道是否有人知道我如何使用 Authlogic gem 从 Rails 中的会话对象访问用户 ID?

我有一个清扫器运行以使特定于用户的缓存片段过期:

 def expire_cache_for(record)
    ActiveRecord::Base.logger.debug "team: #{record.team_id}"
    ActiveRecord::Base.logger.debug("User: #{session}")

    # Expire a fragment
    expire_fragment(:controller => 'groups',  :action => "team_#{record.team_id}_user_#{current_user.id}")
  end

如何使用 Authlogic 从我的清扫器访问用户 ID 以使片段过期?

4

1 回答 1

13

您应该能够通过使用您的 UserSession 模型(或您添加的任何从 Authlogic::Session::Base 派生的模型)来做到这一点:

current_user = UserSession.find
id = current_user && current_user.record.id
于 2009-08-26T04:00:04.507 回答