# Cookie session domain for many sites

**URL:** <https://www.ruby-forum.com/t/cookie-session-domain-for-many-sites/171229>\
**Category:** Rails\
**Created:** [June 29, 2009, 8:33am UTC](https://www.ruby-forum.com/t/cookie-session-domain-for-many-sites/171229 "2009-06-29T08:33:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixel75](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9de053/32.png) [@pixel75](https://www.ruby-forum.com/u/pixel75)\
**Post date:** [June 29, 2009, 8:33am UTC](https://www.ruby-forum.com/t/cookie-session-domain-for-many-sites/171229/1 "2009-06-29T08:33:09Z")

</div>

Hi!

I have an issue that I think right now is like a “rails cliche”:

I’m developing a Network, with a main site and secondary sites. The idea  
is that when you login in the main site, automatically you are login in  
the secondary sites (and viceversa). The obvious solution (one part at  
least) is that when you login, the domain of the cookie will be the  
same.

I read a lot about this issue and possible solutions but nothing works  
for me. First, I have to clarify that I’m using Rails 2.1.1 and for many  
reasons I have with stay put with it. I clarify this because I read  
about solutions but with Rails 2.3 (like this  
[http://ramblingsonrails.com/setting-the](http://ramblingsonrails.com/setting-the) â€¦ n-rails-23)

This other solution:

[http://s2.diffuse.it/blog/show/8\_Settin](http://s2.diffuse.it/blog/show/8_Settin) â€¦ e+in+rails

definitively doesn’t work.

I try even modifing the write\_cookie method in the cookie\_store.erb,  
trying to “force” the domain, but with no positive results (modifying  
@cookie\_options or options or setting new variables).

And when I try to put lines like this in the environment.erb:

ActionController::Base.session\_options[:session\_domain] = ‘.example.com’

and then I try login, I got ActionController::InvalidAuthenticityToken

I use almost all solutions that I found “googling”(?) and I create my  
new recipes “mixing” this solutions but the thing doesn’t work.

Any ideas? Anybody knows one possible solution? I have to use Rails 2.3?

Thanks!!

---

<div class="post-metadata">

**Author:** ![pixel75](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9de053/32.png) [@pixel75](https://www.ruby-forum.com/u/pixel75)\
**Post date:** [August 7, 2009, 9:25am UTC](https://www.ruby-forum.com/t/cookie-session-domain-for-many-sites/171229/2 "2009-08-07T09:25:05Z")

</div>

So what worked? Did you ever solve it?

On Jun 29, 2:33 am, Dario P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
