# Using sessions to give count of current visitors

**URL:** <https://www.ruby-forum.com/t/using-sessions-to-give-count-of-current-visitors/106222>\
**Category:** Rails\
**Created:** [June 7, 2007, 5:47pm UTC](https://www.ruby-forum.com/t/using-sessions-to-give-count-of-current-visitors/106222 "2007-06-07T17:47:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgrosjean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ecc23a/32.png) [@jgrosjean](https://www.ruby-forum.com/u/jgrosjean)\
**Post date:** [June 7, 2007, 5:47pm UTC](https://www.ruby-forum.com/t/using-sessions-to-give-count-of-current-visitors/106222/1 "2007-06-07T17:47:56Z")

</div>

I would like to list the current number of visitors on my site. To do  
this I’m counting the number of sessions that have been updated in the  
last five minutes. Here’s what I’m doing to make it work, please let me  
know if there’s a better way:

First I’ve created a Session model so that I can say Session.find

class Session \< ActiveRecord::Base  
end

Next in my controller I’m searching for all sessions that have been  
updated in the last 5 minutes like this:

def dashboard  
@active\_users = Session.find(:all, :conditions =\> [“updated\_at \> ?”,  
Time.now - 5.minutes]).size  
end

This all seems to work fine, I’m just wondering if it’s somehow a bad  
idea to create the Session model, maybe it make’s active record work  
harder since it may now need to associate a model with each session it’s  
working with?

Thanks for any recommendations.

Jesse
