Share session (cookies) between subdomains in Rails?

As it turns outs ‘domain: all’ creates a cookie for all the different subdomains that are visited during that session (and it ensures that they are passed around between request). If no domain argument is passed, it means that a new cookie is created for every different domain that is visited in the same session and the old one gets discarded. What I needed was a single cookie that is persistent throughout the session, even when the domain changes. Hence, passing domain: "lvh.me" solved the problem in development. This creates a single cookie that stays there between different subdomains.

For anyone needing further explanation, this is a great link:
http://excid3.com/blog/sharing-a-devise-user-session-across-subdomains-with-rails-3/

Leave a Comment