title: Rails session_store multiple domains
body: <p>I have a non-unique (other people must have solved this) issue around sessions. </p>
  
  <p>The scenario is that I have 5 top level domains (domain_a, domain_b, domain_c, domain_d, domain_e), and multiple subdomains under each. My app is required to share sessions between subdomains in the same top level domain e.g sub_1.domain_b.com &amp; sub2.domain_b.com can share, but sub_3.domain_c.com would be a different session. To make matters more complex, it would be ideal if domains a &amp; b, and c &amp; d where also to be able to share sessions.</p>
  
  <p>So the rules:</p>
  
  <ul>
  <li><p>domain_a shares session with domain_b, and with all the subdomains
  within them. Happy for this to be in a cookie_store</p></li>
  <li><p>domain_c shares session with domain_d, and with all the subdomains within them. Happy for this to be in a cookie_store</p></li>
  <li><p>domain_e only shares its session within its subdomains. This needs to be in an active_record_store</p></li>
  </ul>
  
  <p>How can I make this work?</p>
  
  <p>I've tried creating an initialiser with the below in:</p>
  
  <pre><code>MyApp::Application.config.session_store :cookie_store, :key =&gt; '_domain_a', :domain =&gt; '.domain_a.com'
  
  MyApp::Application.config.session_store :cookie_store, :key =&gt; '_domain_b', :domain =&gt; '.domain_b.com'
  
  MyApp::Application.config.session_store :cookie_store, :key =&gt; '_domain_c', :domain =&gt; '.domain_c.com'
  
  MyApp::Application.config.session_store :cookie_store, :key =&gt; '_domain_d', :domain =&gt; '.domain_d.com'
  
  MyApp::Application.config.session_store :active_record_store, :key =&gt; '_domain_e', :domain =&gt; '.domain_e.com'
  </code></pre>
  
  <p>However I am not sure that this is working. domain_e.com session works, which would make sense as it is the last declaration, any thoughts?</p>