# Just one session for one user

**URL:** <https://www.ruby-forum.com/t/just-one-session-for-one-user/125330>\
**Category:** Rails\
**Created:** [January 8, 2008, 10:28am UTC](https://www.ruby-forum.com/t/just-one-session-for-one-user/125330 "2008-01-08T10:28:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 8, 2008, 10:28am UTC](https://www.ruby-forum.com/t/just-one-session-for-one-user/125330/1 "2008-01-08T10:28:29Z")

</div>

I want one user to have one session only. If user signs in again on some  
other station, it should automatically log off from previous session.  
I really dont know how to implement this.  
Somebody please guide me. I am storing my session in DB.  
Thanks.

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [January 8, 2008, 11:53am UTC](https://www.ruby-forum.com/t/just-one-session-for-one-user/125330/2 "2008-01-08T11:53:25Z")

</div>

On Jan 8, 2008, at 10:28 AM, Vapor … wrote:

> I want one user to have one session only. If user signs in again on  
> some  
> other station, it should automatically log off from previous session.  
> I really dont know how to implement this.  
> Somebody please guide me. I am storing my session in DB.

You want to delete the rest of sessions for that user, but in a  
regular setup of the AR session store the user\_id associated to a  
record is marshalled as session data.

You’d need to add a custom column user\_id in the sessions table and  
maintain that column somehow, for example in an after\_filter in  
ApplicationController. This solution is explained in The Rails Way.

– fxn
