Feb 29, 2008
Photo_46_small monki(Wesley... 4 posts

Topic: Advanced Rails Recipes / Sessions won't persist after setting session_domain

Mike:

I tried a couple different things in my hosts file.

I tried just using ‘localhost’, ‘subdomain.localhost’, ‘test.localhost’ and had no luck. Then thinking that perhaps it was an issue of lacking a tld I tried ‘localhost.host’, ‘subdomain.localhost.host’ and ‘test.localhost.host’.

I’m not sure where things get off in this configuration, but none of those variations ended up working.

When I changed things around to use ‘domain.dev’, ‘subdomain.domain.dev’ and ‘test.domain.dev’ things worked properly. I suppose you might or might not need to flush your dns cache if you are making a lot of changes to this stuff, but it shouldn’t need it when you first define them.

Hope that clears it up.

Morten:

1) I haven’t done anything with multiple fully customized domains. You can use the session_domain setting still, but it will make the same cookie be in effect across all the domains. Just depends what you want it to act like whether or not you should do this.

2) I believe he just means its a bad idea to let somebody register to use ‘domain.domain.com’, like letting somebody use ‘google.google.com’ or something. It doesn’t break anything, but it could be confusing for users as they would likely think that this was an ‘official’ page, rather than that of a particular user.

3) I think you are on the right track there. Have the ssl for your main domain and make them login through this, but have all the subdomains reference the same cookie to see if you are logged in. I’m not using ssl, but I am expecting users to sign in through the main domain rather than a subdomain.

 
Feb 27, 2008
Photo_46_small monki(Wesley... 4 posts

Topic: Advanced Rails Recipes / Sessions won't persist after setting session_domain

Figured it out. It works fine as long as you don’t try to set the session_domain to something related to localhost. I ended up using ’.mydomain.dev’ and adding the entries to the host for development and ’.mydomain.com’ for production and it works as expected. So, perhaps a note to avoid localhost would be in order.

 
Feb 26, 2008
Photo_46_small monki(Wesley... 4 posts

Topic: Advanced Rails Recipes / Sessions won't persist after setting session_domain

Certainly. I may well have mucked up some settings some where too, but I had tried any number of variations/alternatives with no real difference. I’d be more than happy to provide any other info you might need to replicate the problem, and I look forward to actually knowing I’m not just crazy :)

 
Feb 25, 2008
Photo_46_small monki(Wesley... 4 posts

Topic: Advanced Rails Recipes / Sessions won't persist after setting session_domain

I’ve tried a number of different combinations of setting options to try and get recipe 65 working, with no luck. I’m trying with CookieStore again at present, but tried with activerecordstore as well and had no better luck.

As soon as I set the session_domain, for instance by following the example in the recipe, to:
ActionController::Base.session_options[:session_domain] = ’.example.com’

Then sessions are no longer persisted, at all. It doesn’t store any cookie for the session at all and you get a new session with every request. If I remove it sessions work again, but then of course I get separate sessions for each subdomain. I am on edge rails (updated as of this morning).

Any help would be greatly appreciated as its driving me quite mad.

4 posts