The key is really how you set the session cookie, because you cannot delete the subdomain cookie (username.myapp.com) from the top level domain (myapp.com). To solve this problem, you want all of your shared session cookies to be set in the myapp.com domain. To do this, configure the sessions as follows:
Rails.application.config.session_store :cookie_store, :domain => 'myapp.com'
That way, when you destroy the session ( session[:id] = nil ), you delete the shared cookie. I believe that you will also have to delete the session using session [: id] instead of session [: user_id].
Pan thomakos
source share