Navigation

Entries in subdomain (1)

Wednesday
Jun012011

Subdomain routing with rails 3.1

I wanted to use subdomain based routing on my current rails 3.1rc project and was getting some very odd behavior. Everything locally worked great when I was using lvh.me to point to local host and using custom subdomains and routes. I used the tutorial found here http://asciicasts.com/episodes/221-subdomains-in-rails-3 to help me with everything and made my own unimportant changes as needed. When I pushed all this up to heroku's bamboo stack, I experienced quite a few errors, but mainly a TypeError (can't convert Symbol into String).

After trying to figure it out on my own, I contacted the heroku support team and they advised me to move it to the brand new cedar stack launched that morning. I did and still experienced the same issue. However, and this is where things really get weird, it stopped working locally. I was really shooting in the dark on this as I had no idea where the error was occurring. I wasn't sure if it was my code or something inside rails or what. After commenting out pretty much every piece of code I had written, I finally found the error. 

At the bottom of the tutorial, he talks about setting the domain for the session cookie so that it is accessible on all domains. The problem is the symbol assigned to the domain key in the hash passed to the session_store method. I guess this worked in 3.0 but is broken in 3.1. By making the following change (setting the domain to your specific domain), everything started working as I expected.

The problem here is that when I am testing locally, I have to remember to change this to lvh.me or set my hosts file to point my personal domain to 127.0.0.1. At least it is working agian.