The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Who is online, really?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eric Stewart

Posts: 72
Nickname: estewart
Registered: Dec, 2003

Eric Stewart is software developer from Austin, Texas.
Who is online, really? Posted: Dec 15, 2005 1:07 PM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eric Stewart
Latest Posts From Ponderings On Ruby

Advertisement

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.

@sessions = CGI::Session::ActiveRecordStore.session_class.find(:all)
@session_pages = Paginator.new self, @sessions.size, 10, @params['page']

Of course, I was tring to be all fancy and show a paginated listing of active sessions.

Then..

Slap a nice view in

Put a nice view in and access your sessions data (in helper or rhtml template) like so:


  session.data['user'].fullname 

Read: Who is online, really?

Topic: Coding Standards -- Keep It Simple Previous Topic   Next Topic Topic: Rails 1.0: We finally made it there!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use