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 ?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With