Forum: Ruby on Rails Online users and sessions - logic help

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Scott H. (Guest)
on 2007-02-23 18:41
Hello G.s,

I have an application which lets users login . In order to see how many
users are online (active in the last 20 mins) I have a before_filter on
every page which updates a column in the user table called

This is a little silly and is really slowing things down.

Here are my aims:

•  I need to create a list of all the users active in the last 20 mins
•  I need to be able to see when a user was ‘online’

Obviously I need to start tracking sessions, but I really need some help
with the logic of it

Here is what I’m thinking so far…


* When they log in I first check to see if there is a session already
assigned to that user
  * (If there is – I destroy it)
* I then create a new session and assign the user id to it.

“Who’s online”: I can then pull out a list of all the sessions which
have been updated in the past 20 mins along with the user id

When they log out, I destroy the session


But this doesn’t solve my problem of seeing when a person was last
‘online’ if I have destroyed the session

Any suggestions?
Luke I. (Guest)
on 2007-02-23 20:45
(Received via mailing list)
You've already said that you destroy sessions when they log in if the
session still exists... so just don't destroy the session when someone
out.  You're left with an idle session that exists until the next time
log in this way, but you can always set up some kind of scheduled thing
(varies depending on OS) that will go in and clean up any sessions that
haven't had activity in <X> amount of time.
This topic is locked and can not be replied to.