# Rails configuration for sessions

**URL:** <https://www.ruby-forum.com/t/rails-configuration-for-sessions/66605>\
**Category:** Rails\
**Created:** [August 27, 2006, 7:52pm UTC](https://www.ruby-forum.com/t/rails-configuration-for-sessions/66605 "2006-08-27T19:52:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [August 27, 2006, 7:52pm UTC](https://www.ruby-forum.com/t/rails-configuration-for-sessions/66605/1 "2006-08-27T19:52:58Z")

</div>

I’m trying to get the configuration done for sessions but I can’t seem  
to find any documentation on how to do it beyond the merest of basics.

I would rather have something that would NOT persist a marshalled object  
to the database since that’s just not something I want to do. I want to  
be able to read the data for one.

But there’s really nothing to identify how that is done.  
Or even identified in the Rails::Configuration because:  
– it’s missing from the installation (no docs?)  
– there’s nothing via the internet that I can find which actually  
specifies session configuration. This does not:  
[http://glu.ttono.us/articles/2006/05/22/configuring-rails-environments-the-cheat-sheet](http://glu.ttono.us/articles/2006/05/22/configuring-rails-environments-the-cheat-sheet)

And I can’t find anything that that really discusses how to get  
configurations done.

---

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [August 27, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/rails-configuration-for-sessions/66605/2 "2006-08-27T20:31:03Z")

</div>

Hello Tom.  
Stupid question, or observation more to the point, but,  
[http://wiki.rubyonrails.org/rails/pages/HowtoChangeSessionOptions](http://wiki.rubyonrails.org/rails/pages/HowtoChangeSessionOptions) …  
where its always lived 😉 \*

```
Regards
Stef

```

(\* yes yes, I know that the wiki went through and is still kinda going  
through a re-juggle but… you get the point 😉

---

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [August 27, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/rails-configuration-for-sessions/66605/3 "2006-08-27T20:20:14Z")

</div>

Tom A. wrote:

> I’m trying to get the configuration done for sessions but I can’t seem  
> to find any documentation on how to do it beyond the merest of basics.
> 
> I would rather have something that would NOT persist a marshalled object  
> to the database since that’s just not something I want to do. I want to  
> be able to read the data for one.
> 
> But there’s really nothing to identify how that is done.  
> Or even identified in the Rails::Configuration because:  
> – it’s missing from the installation (no docs?)  
> – there’s nothing via the internet that I can find which actually  
> specifies session configuration. This does not:  
> [http://glu.ttono.us/articles/2006/05/22/configuring-rails-environments-the-cheat-sheet](http://glu.ttono.us/articles/2006/05/22/configuring-rails-environments-the-cheat-sheet)
> 
> And I can’t find anything that that really discusses how to get  
> configurations done.

Any of the currently available authentication generators & engines  
should provide you with the foundation for all this information.

You don’t have to store the entire User object in the session data, I  
dont, especially since some of that data might not be useful or secure  
inside a session.

Typically I just store the user\_id, security\_token, and token\_expiry.

And the session hash works just like anyother has in rail, params for  
instance.

---

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [August 27, 2006, 10:09pm UTC](https://www.ruby-forum.com/t/rails-configuration-for-sessions/66605/4 "2006-08-27T22:09:13Z")

</div>

> Thanks. I’ve gone through that and found that I can easily change the  
> storage to a database, but it’s always a marshalled object.
> 
> What I’m trying to learn/find is how to store session data in a NON  
> marshalled object, which was the point of my original post. I’m sorry  
> if I didn’t make that clear. However, the initial page here certainly  
> doesn’t address it and the closest thing I can find is:

How else would you store something like a session without serializing  
it in some way? Just curious what you are thinking.

Chris

---

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [August 27, 2006, 10:39pm UTC](https://www.ruby-forum.com/t/rails-configuration-for-sessions/66605/5 "2006-08-27T22:39:15Z")

</div>

Hello Tom,  
So, to clarify, what your getting at/asking for is a way to store an  
arbitrary complex data structure such as a session without having it  
marshalled, so that each field is stored as an int, numeric, varchar  
etc, as appropiate ? Two ways spring to mind in that case.

```
The first way -I- can think of doing that is to create an database

```

table (say) mySession and corresponding model, and then populate it in  
much the same way as every other object. If you think about it (and  
assuming I have the cut o’ your jib here) then this has problems  
(needing to make sure that you know your session ‘fields’ ahead of time,  
no adding in ‘one more field’ to the session ;). This would have to be  
keyed by (say) session id in the application.rb but… should be do-able.

```
If your -not- tied to storing sessions in the database (no pun

```

intended for perl programmers 😉 then you could try overloading/writing  
your own session/session\_store methods so that they spit out YAML to the  
tmp directory instead of a marshalled object. I think that may be a gain  
actually _hrms_ oh well, yes 🙂

```
Of course, these are only theories at the present, feel free to

```

scream and tell me why they wouldn’t work or perhaps someone else here  
already has.

```
I must admit, I -personally- don't like the whole 'blobs' in my

```

database, but, thats jst me. Let me know if you need any more  
thoughts/help/code.  
Regards  
Stef

---

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [August 27, 2006, 10:53pm UTC](https://www.ruby-forum.com/t/rails-configuration-for-sessions/66605/6 "2006-08-27T22:53:17Z")

</div>

Stef T wrote:

> assuming I have the cut o’ your jib here) then this has problems  
> (needing to make sure that you know your session ‘fields’ ahead of time,  
> no adding in ‘one more field’ to the session ;). This would have to be  
> keyed by (say) session id in the application.rb but… should be do-able.

I think this is the direction to pursue. I think BLOBs are a horrible  
idea in databases unless you can guarantee they will only in in  
existence for a short period and can be easily reconstructed. Easily  
also means without inconvenience…

I’ll see what I can come up with on my adventures.  
Thanks.

---

<div class="post-metadata">

**Author:** ![tma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ed655f/32.png) [@tma](https://www.ruby-forum.com/u/tma)\
**Post date:** [August 27, 2006, 9:53pm UTC](https://www.ruby-forum.com/t/rails-configuration-for-sessions/66605/7 "2006-08-27T21:53:12Z")

</div>

Stef T wrote:

> Hello Tom.  
> Stupid question, or observation more to the point, but,  
> [http://wiki.rubyonrails.org/rails/pages/HowtoChangeSessionOptions](http://wiki.rubyonrails.org/rails/pages/HowtoChangeSessionOptions) …  
> where its always lived 😉 \*

Thanks. I’ve gone through that and found that I can easily change the  
storage to a database, but it’s always a marshalled object.

What I’m trying to learn/find is how to store session data in a NON  
marshalled object, which was the point of my original post. I’m sorry  
if I didn’t make that clear. However, the initial page here certainly  
doesn’t address it and the closest thing I can find is:

[http://weblog.textdrive.com/article/196/on-rails-sessions](http://weblog.textdrive.com/article/196/on-rails-sessions)

which still misses the mark.
