I am looking into creating a website similar to a chat program. I know
when the user logs in. However, the user can log out any of the
Logout link - This one is easy to handle
User closer browser window
User hits the back button
User loses his/her internt connection.
Is there a way within rails to handle the latter three user actions?
Usually, the last three cases are handled with a timeout of some
kind. If the user’s browser doesn’t interact with the server at all
in a specific amount of time, then the server expires the session.
How do I know when the session expires? In the case of a chat room, I
would have to update the database or something so other people in the
room see that that person is no longer in the room.
You might want to use railscron to expire sessions that have not been
updated in 20 minutes.
Dan K. mailto:[email protected]
A simple solution to expire sessions is to set expiry in controllers.
session :session_expires => 2.minutes.from_now
While nice, this is not a great way to keep a “who’s online” list. It’s
probably safest to keep an online status in the users table, and update
to Time.now each time a user browses to a new page. That way “who’s
resolves to User.find(:conditions => [‘last_hit_server_at’ > ?’,
View this message in context:
Sent from the RubyOnRails Users forum at Nabble.com.