Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authlogic accessing user id in session object

I was wondering if anyone knows how I can access the user ID from the session object in Rails using the Authlogic gem ?

I have a sweeper that runs to expire a cache fragment specific to a user:

 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

How can I access the user ID from my sweeper to expire the fragment using Authlogic ?

like image 461
Andrew Cetinic Avatar asked Aug 22 '09 12:08

Andrew Cetinic


1 Answers

You should be able to do this by using your UserSession model (or whatever model you've added that derives from Authlogic::Session::Base):

current_user = UserSession.find
id = current_user && current_user.record.id
like image 182
John Pignata Avatar answered Nov 05 '22 23:11

John Pignata