# Shared sessions and rails2

**URL:** <https://www.ruby-forum.com/t/shared-sessions-and-rails2/126677>\
**Category:** Rails\
**Created:** [January 21, 2008, 10:54am UTC](https://www.ruby-forum.com/t/shared-sessions-and-rails2/126677 "2008-01-21T10:54:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![apie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@apie](https://www.ruby-forum.com/u/apie)\
**Post date:** [January 21, 2008, 10:54am UTC](https://www.ruby-forum.com/t/shared-sessions-and-rails2/126677/1 "2008-01-21T10:54:05Z")

</div>

Hi all

How would you go about sharing a session between two rails2  
applications? I  
am using restful\_authentication.

A point in the direction of some relevant blogs would also be a great  
help.

Regards  
Ivor

---

<div class="post-metadata">

**Author:** ![apie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@apie](https://www.ruby-forum.com/u/apie)\
**Post date:** [January 21, 2008, 11:19am UTC](https://www.ruby-forum.com/t/shared-sessions-and-rails2/126677/2 "2008-01-21T11:19:58Z")

</div>

On 21 Jan 2008, at 09:52, Ivor P. wrote:

> Hi all
> 
> How would you go about sharing a session between two rails2  
> applications? I am using restful\_authentication.
> 
> A point in the direction of some relevant blogs would also be a  
> great help.

This largely depends on what backend you use. If you set the session  
key (ie in the initializer block, stick  
config.action\_controller.session = { :session\_key =\> ‘\_some\_key’} )  
then both apps should use the same cookie to track the session. You’re  
also need to be serving both apps from the same host (so that the  
browser does actually send the same cookies to both apps, otherwise  
you don’t have a hope in hell)  
What happens next largely depends on what backend you are using to  
store sessions:

- cookiestore: the cookie is the session, so if your apps can share  
cookies you should be golden
- activerecordstore/other db backed session stores: both apps will  
need access to a common database
- pstore: you’ll need to set the apps to write the session files to  
some common directory both can access
- memcache/drbstore: I’ve never used these.

So, in summary it’s probably possible. You should also be aware that 2  
simultaneous actions can result in the session being slightly clobbered.

Fred
