Knowing when a user is logged in

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
following ways:

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?

Thanks!

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.

Tim

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.

Chris

You might want to use railscron to expire sessions that have not been
updated in 20 minutes.

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

A simple solution to expire sessions is to set expiry in controllers.
E.g.,

class MyController
session :session_expires => 2.minutes.from_now
end

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
it
to Time.now each time a user browses to a new page. That way “who’s
online”
resolves to User.find(:conditions => [‘last_hit_server_at’ > ?’,
2.minutes.ago]).

View this message in context:
http://www.nabble.com/Knowing-when-a-user-is-logged-in-tf2000253.html#a5498376
Sent from the RubyOnRails Users forum at Nabble.com.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs