title: How to do automatic-sign-in for users who register and get transferred to their account subdomain
body: <p>I'm building a multi-tenant app where accounts are scoped under subdomains. Assuming <em>acme.com</em> is my app and <em>Elmer</em> is my user, when Elmer registers at acme.com he is transferred to elmer.acme.com. I want to sign Elmer in after he registers, but I'm having a hard time. I'm using cookies. Here's my sign in method:</p>
  
  <pre><code>  def sign_in(user)
      cookies.permanent[:remember_token] = user.remember_token
      current_user = user
    end
  </code></pre>
  
  <p>Here's part of my Users#create method where users get signed in.</p>
  
  <pre><code>if @user.save
    sign_in(@user)
    redirect_to root_url(subdomain: @user.subdomain)
  end
  </code></pre>
  
  <p>The cookie is getting set when Elmer is still at <em>acme.com.</em> When Elmer is redirected to <em>elmer.acme.com</em> the cookie is not valid.</p>
  
  <p>I can set <code>domain: :all</code> in my <code>session_store</code>, but this breaks a requirement. It would mean Elmer will be signed into <code>elmer.acme.com</code>, <code>buggs.acme.com</code>, and essentially <code>*.acme.com</code>. Elmer's session cookie should only be valid for <em>elmer.acme.com</em> and/or <em>acme.com</em>.</p>
  
  <p>Any idea how to achieve this? I'm running Rails 3.2 with Ruby 1.9.3.</p>