Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subdomain cookie sharing in Rails 3 is not working (on Heroku)?

I'm trying to have cookies on my site dapshare.com work for both the root address and the 'www' subdomain.

A lot of other stackoverflow answers (and the great Railscasts vid on this topic) have suggested adding this line to session_store.rb:

Dapshare::Application.config.session_store :cookie_store, :key => '_dapshare_session', :domain => :all

This doesn't seem to make a difference: if I log in at dapshare.com, I still am not logged in at www.dapshare.com.

Am I doing something wrong here? I am using the following code to store information in the cookie:

cookies.permanent.signed[:thing_to_store] = store_information

Thanks for any help!

like image 786
Rob d'Apice Avatar asked Apr 12 '11 03:04

Rob d'Apice


1 Answers

Short answer: using the 'cookies[:new_cookie] =' does not seem to grab the domain from the session_store config settings.

I added the :domain to the new cookie and it now works:

cookies.permanent.signed[:new_cookie] = {:value => new_value, :domain => ".dapshare.com"}

For anyone else reading, you also need to specify the domain when deleting the cookie

cookies.delete :new_cookie, :domain => ".dapshare.com"

(Thanks for your help with diagnosis Andrew Marshall.)

like image 155
Rob d'Apice Avatar answered Oct 28 '22 01:10

Rob d'Apice