How to track online users in Rails?

前端 未结 1 1009
栀梦
栀梦 2021-02-09 20:15

This was always a problem for me, as rails doesn\'t have some mechanisms for session tracking like java frameworks do, what methods do you use to track who is currently logged o

1条回答
  •  甜味超标
    2021-02-09 21:10

    If you are using the active_record_store for your sessions, you can try something like this:

    sessions = CGI::Session::ActiveRecordStore::Session.find(:all, :conditions => ["updated_at >= ?", 15.minutes.ago], :order => "created_at ASC")
    sessions.each do |session|
      if session.data[:user]
        online_users << User.find(session.data[:user])
      end
    end
    

    0 讨论(0)
提交回复
热议问题