# How to use an active record store session model?

**URL:** <https://www.ruby-forum.com/t/how-to-use-an-active-record-store-session-model/190045>\
**Category:** Rails\
**Created:** [June 12, 2010, 12:12am UTC](https://www.ruby-forum.com/t/how-to-use-an-active-record-store-session-model/190045 "2010-06-12T00:12:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [June 12, 2010, 12:12am UTC](https://www.ruby-forum.com/t/how-to-use-an-active-record-store-session-model/190045/1 "2010-06-12T00:12:05Z")

</div>

I have a toy rails app, 2.3.5 on Debian ‘squeeze’, that uses the  
ActiveRecord session store. I can see that it set cookies and  
inserts rows into the database table ‘sessions’.

Inside a controller, how do I acquire a reference to the model object  
representing the current session? This used to be possible by calling  
‘session.model’ but in 2.3.5 there is no ‘model’ method on the session  
object.

## Thanks

Nick

---

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/how-to-use-an-active-record-store-session-model/190045/2 "2010-06-17T16:22:38Z")

</div>

Let me know if you figure this out - I’m having the same problem.

– Garth

---

<div class="post-metadata">

**Author:** ![nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://www.ruby-forum.com/u/nick)\
**Post date:** [June 18, 2010, 11:37pm UTC](https://www.ruby-forum.com/t/how-to-use-an-active-record-store-session-model/190045/3 "2010-06-18T23:37:43Z")

</div>

On 2010-06-16 08:56, Garth wrote:

> Let me know if you figure this out - I’m having the same problem.

```
  session[:fish] = ! session[:fish]
  @site_session = request.env['rack.session.record']

```

The fishy line, or equivalent, seems to be required to ensure that Rails  
creates a  
session object.

I don’t know that this is the best way to get the session model  
object. It’s pretty deranged compared to ‘… = session.model’.

> – Garth

–  
Nick
