开发者

Rails 3: Ending user session once a user closes his/her browser or page?

Is there any way of ending a user session once a user closes his browser or page he was on?

p.s I use authlogic as my authentication plug in.

the reason 开发者_Python百科i ask is because i want to lock a table column when its being edited and don't want it to be released until the user is finished making his changes to the row or he closes him browser or goes to another page etc.

Thanks


No, you can't get a notification when a browser window closes. If you think about this it makes sense, because there are many ways a user might terminate their browsing experience. For instance, they may simply lose connectivity - in which case there is no way to notify your application that this has happened. Also, it's impractical for a browser to send every single window that is open a notification that it is terminating.

That said, if you are set on this user interaction, I would recommend having an Ajax request that pings your server to notify your application that the user is still active and the table lock should not be released. For instance, set the interval to two seconds. If you don't receive a new ping within 3-4 seconds, release the lock.

I would recommend you aim for a different approach though. Creating long lasting row/table locks is not safe. If I were you, I would structure the user interaction in a different way to avoid this lock entirely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜