# Sharing sessions across rails apps 2.3.2

**URL:** <https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897>\
**Category:** Rails\
**Created:** [May 13, 2009, 7:00pm UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897 "2009-05-13T19:00:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![biot023](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@biot023](https://www.ruby-forum.com/u/biot023)\
**Post date:** [May 13, 2009, 7:00pm UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897/1 "2009-05-13T19:00:57Z")

</div>

I’ve done this in 2.2, but cannot figure it out for 2.3.2:

Basically, I want to be able to share session data across a couple of  
apps.  
The way I did this in 2.2 was to create a view called sessions in the  
second app that read the sessions table of the first app.  
This done, I could tell them both to use active record sessions, and,  
lo! I had a shared session.  
Once I’d written a little routine to swap between apps (to basically  
clean out the session apart from user ids), I could then happily swap  
back and forth between them.  
The trouble is, rails has moved on to 2.3.2, and I’m having the very  
devil of a time getting something like this working again.  
I’m using the same view-as-sessions-table technique, and I have both  
apps sessions set to the same key and secret in the initializers/  
directory, but it just isn’t working.  
Can anyone offer any advice as to what I could try next?  
Cheers,  
Doug.

---

<div class="post-metadata">

**Author:** ![biot023](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@biot023](https://www.ruby-forum.com/u/biot023)\
**Post date:** [May 13, 2009, 7:33pm UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897/2 "2009-05-13T19:33:19Z")

</div>

On 13 May 2009, at 18:00, Doug L. wrote:

> clean out the session apart from user ids), I could then happily swap  
> back and forth between them.

Don’t you need to be making the session cookie have a different domain  
so that the cookie is sent to both apps ? I think some of the minutiae  
of session options changed slightly with 2.3.2

Fred

---

<div class="post-metadata">

**Author:** ![biot023](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@biot023](https://www.ruby-forum.com/u/biot023)\
**Post date:** [May 13, 2009, 8:56pm UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897/3 "2009-05-13T20:56:58Z")

</div>

That could well be part of it, but I’m afraid I’m not sure I follow you.  
How would I go about doing that?  
(I didn’t need to with my old approach.)  
Cheers,  
Doug.

---

<div class="post-metadata">

**Author:** ![biot023](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@biot023](https://www.ruby-forum.com/u/biot023)\
**Post date:** [May 13, 2009, 9:47pm UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897/4 "2009-05-13T21:47:03Z")

</div>

On May 13, 7:56 pm, Doug L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> That could well be part of it, but I’m afraid I’m not sure I follow you.  
> How would I go about doing that?  
> (I didn’t need to with my old approach.)

Ah, we may not be talking about the same thing. Are these apps on  
different subdomains (eg [app1.example.com](http://app1.example.com), [app2.example.com](http://app2.example.com)),  
different domains, or on the same domain ([example.com/app1](http://example.com/app1) &  
[example.com/app2](http://example.com/app2)) ?

Fred

---

<div class="post-metadata">

**Author:** ![biot023](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@biot023](https://www.ruby-forum.com/u/biot023)\
**Post date:** [May 13, 2009, 9:56pm UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897/5 "2009-05-13T21:56:59Z")

</div>

They’re on the same machine, although I may want to move them at some  
point.

---

<div class="post-metadata">

**Author:** ![biot023](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@biot023](https://www.ruby-forum.com/u/biot023)\
**Post date:** [May 13, 2009, 10:22pm UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897/6 "2009-05-13T22:22:26Z")

</div>

On May 13, 8:56 pm, Doug L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> They’re on the same machine, although I may want to move them at some  
> point.

that doesn’t quite answer the question - even though they are on the  
same machine any of the 3 scenarios I mentioned could be in effect.  
What it boils down to in the end is cookies: there is a cookie that  
tells rails which row from the sessions table to use and if both apps  
aren’t getting the same value out of this cookie then although the  
sessions are backed by the same table they will appear as different  
users.

Fred

---

<div class="post-metadata">

**Author:** ![biot023](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@biot023](https://www.ruby-forum.com/u/biot023)\
**Post date:** [May 13, 2009, 11:46pm UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897/7 "2009-05-13T23:46:08Z")

</div>

I had something very similar on one of my applications with 2.3.2 the  
action\_controller.session has changed and its now just :domain  
and :key :

config.action\_controller.session = {  
:domain =\> ‘.me.com’,  
:key =\> ‘\_my\_session’,  
:secret =\> ‘long string’  
}

This shares the [me.com](http://me.com) cookie with \*.me.com so [www.me.com](http://www.me.com) or  
[secure.me.com](http://secure.me.com) or [me.com](http://me.com)…

This goes in your environments/product.rb or development.rb files…

---

<div class="post-metadata">

**Author:** ![biot023](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@biot023](https://www.ruby-forum.com/u/biot023)\
**Post date:** [May 14, 2009, 12:23am UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897/8 "2009-05-14T00:23:30Z")

</div>

So if I have (locally) my apps all called things like “app1.local” and  
“app2.local”, then I could set the domain to “.local”, which would  
generate a “local” cookie that would be available to both apps, enabling  
them to share a session?  
Sorry if I’m labouring the point – I’ve had my head in this all day &  
am correspondingly slow tonight!  
& thankyou,  
Doug.

---

<div class="post-metadata">

**Author:** ![biot023](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ab992/32.png) [@biot023](https://www.ruby-forum.com/u/biot023)\
**Post date:** [May 13, 2009, 11:32pm UTC](https://www.ruby-forum.com/t/sharing-sessions-across-rails-apps-2-3-2/167897/9 "2009-05-13T23:32:24Z")

</div>

Ah, I see, sorry – well, they’ll be on the same machine, but that is on  
a local network (these are internal apps), and they are accessed by  
names like “app1”, “app2”, with the local server’s DNS resolving them to  
the server address, and passenger and phusion taking over from there.  
That’s the idea, anyway – I had the proof-of-concept working, but  
needed to upgrade the apps to 2.3.2 before deploying them.  
You can probably tell this isn’t my area of expertise!  
& thanks for your continued advice.  
Doug.
