This post originated from an RSS feed registered with Ruby Buzz
by Eric Stewart.
Original Post: Who is online, really?
Feed Title: Ponderings On Ruby
Feed URL: http://blog.eric-stewart.com/category/programming-ruby.rss
Feed Description: This is the Ruby related section of Eric Stewart's weblog. These entries will be the commentary of a long time Java/C++ programmer that started exploring Ruby in 2003.
Courtenay was pondering today how to figure out who is online in your Rails app. I’m liking his solution better thank what I thought up on this a few days back, but since he asks….
My solution was a bit quicker and dirtier. I wanted to jump in and get a list without that oh-so-tedious (wink) process of creating a new model class. So, what I did was:
Make sure I was using ActiveRecordStore for sessions.
Just as Courtenay describes, create your sessions table:
rake create_sessions_table
But remember, I was trying to avoid an actual model class. Moving on…
Create a handy controller action
This is the meat of it. In the action I want to use to list active sessions I do something like this.