You can use before_filter catch the user every time the-user makes a request to the server. Using updated_at attribute of current_user ( or whatever else you make invoke the get the logged_in user )
a simple example using before_filter:
class RubyDevelopersController < ChatRoomController
# every time the request hits the server a call is sent to register the user
before_filter :register_user
private
def register_user
# the current_user's model is updated with the name
# of the chatroom he's hidding in.
# remember that this call also updates updated_at field of the current_user
current_user.update_attribute( :current_chatroom, 'ruby_developers' )
end
def ative_users_in_ruby_developers_chatroom
# find all users in the current chatroom that has been updated_at in the last 5 minutes.
Users.find( :all, {
:conditions => ["current_chatroom = ? and updated_at > ?",'ruby_developers', 5.minutes.ago ],
:sort => 'updated_at'
})
end
end
also see:
http://railsforum.com/viewtopic.php?pid=66001