title: Setting a cookie on all subdomains in Rails 4 and Ember
body: <p>We have a Rails application that is the API component running on <code>api.domain.com</code> and a front-end application in Ember.js running on <code>www.domain.com</code>.</p>
  
  <p>When Ember.js sends a POST request to a route in the API, <code>/events</code>, we want the API to set a cookie to remember a unique user identifier.</p>
  
  <p>Hence this method in the Events controller:</p>
  
  <pre><code>def set_tracking_cookie
    cookies[:our_company_distinct] = {
      value: create_identifier,
      expires: 1.year.from_now,
      domain: :all
    }
  end
  </code></pre>
  
  <p>As you see, the cookie is set on the entire domain, and is set to expire in a year.</p>
  
  <p>The point is that the next time Ember queries the API, it will be able to read this cookie. However, this is not the case.</p>
  
  <p>Each time the front-end queries the API, the API is unable to find the cookie, nor does it show in the cookies in my developer tools.</p>
  
  <p>The Ember requests set the <code>Access-Control-Allow-Credentials</code> header to <code>true</code>, and I can confirm that the cookie is indeed sent in the response from the API with the correct values for domain, name, path, expiry, etc.</p>
  
  <p>Am I missing something?</p>
  
  <p>Thanks!</p>