Extension to book login code: list of online users?

Hi.

I’ve been, fruitlessly, trying to extend the login code from the Agile
book. What I’m trying to do, is create a list of logged in users.

My idea is to the list of sessions. However, many sessions seem to be
outdated. I believe the best way would be to get a list of sessions that
have been active in, say, the last 15 minutes.

Question is: how can I do this? Any hints would be greatly appreciated.

Regards,

Denis D.

Denis D. wrote:

My idea is to the list of sessions. However, many sessions seem to be
outdated. I believe the best way would be to get a list of sessions that
have been active in, say, the last 15 minutes.

Question is: how can I do this? Any hints would be greatly appreciated.

Sessions aren’t ActiveRecord objects, but for this purpose you can
pretend. Assuming you are storing your sessions in the database, get the
results with raw sql.

@active_sessions = ActiveRecord::Base.find_by_sql [“SELECT * FROM
sessions WHERE updated_at > ?”, Time.now - 15.minutes]

I’d be interested in hearing how you get from this point to user ids.

Ray