# Restful\_authentication+ personnalized database session store

**URL:** <https://www.ruby-forum.com/t/restful-authentication-personnalized-database-session-store/146102>\
**Category:** Rails\
**Created:** [August 17, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/restful-authentication-personnalized-database-session-store/146102 "2008-08-17T22:26:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [August 17, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/restful-authentication-personnalized-database-session-store/146102/1 "2008-08-17T22:26:14Z")

</div>

I’m using restful\_authentication and database session store with rails  
2.1.0. It works well and I’m trying too add the user\_id in the session  
table.  
For that, I have created app/models/session.rb and I have set the  
user\_id value in app/controllers/sessions\_controller.rb when the user is  
logged in:  
def create  
self.current\_user = User.authenticate(params[:login],  
params[:password])  
if logged\_in?  
session.model.user\_id = current\_user.id

My problem is that when I log in, the user\_id field is not filled in the  
sessions table. I have tried many things but I didn’t manage to have it  
working.

Could someone give me any idea to fix the problem or to investigate it?

Thanks

John

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [August 19, 2008, 10:06am UTC](https://www.ruby-forum.com/t/restful-authentication-personnalized-database-session-store/146102/2 "2008-08-19T10:06:15Z")

</div>

Try to assign your user\_id in application.rb: session.model.user\_id =  
current\_user.id

You should be aware that when a user logout, the associated entry will  
be removed from your sessions table. So you won’t keep track of these  
users …

Joe

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [August 19, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/restful-authentication-personnalized-database-session-store/146102/3 "2008-08-19T16:14:04Z")

</div>

Joe Betsik wrote:

> Try to assign your user\_id in application.rb: session.model.user\_id =  
> current\_user.id
> 
> You should be aware that when a user logout, the associated entry will  
> be removed from your sessions table. So you won’t keep track of these  
> users …
> 
> Joe

Thank you Joe for your response. I tried to move the call in  
application.rb but from there it can’t access the model (sesion.model).

In fact I just want to have a log with all users which logs into my  
application with the date. I don’t need all other fields stored in the  
session and of course I don’t want entries of this log deleted when a  
user log out!

I don’t have enough experience with RoR to realize if I’m following a  
right path with my sessions stored in a database. I thought I could use  
this mechanism to avoid to rewrite a lot of code very similar to that  
exist ( I appreciate the DRY concept very much!).

Thanks for any advice,

John
