Sunday, December 03, 2006

Pudding with proper URL's

I've finally made the switch to the fancy "subdomain as account key" style of URL's for Pudding. Previously, when you signed up for an account the URL you would work from looked like this:

http://www.ataraxispudding.com/company/yourcompanyname

Kinda ghetto!

The URL will now look like this:

http://yourcompanyname.ataraxispudding.com

I just finished squashing the last of the bugs related to change. I need to make a few more tweaks to the way the application reacts to "www.ataraxispudding.com", but the internals of the app are sound.

A few things about the transition
  • Setting up the server for wildcard subdomains. I've seen the configuration addition for Apache, and it looks dead simple. (It's like 1 line of configuration.) Unfortunately (for this situation) I'm using lighttpd, and the setup turned out to be a little more complicated. Luckily, Graeme Mathieson, has a really good tutorial for setting up OSX with a local name server (Thanks Tyler!), which you then use to work the wildcard subdomain magic. The write up has one small portion that confused me (and caused me to spend a hour scratching my head), so I'm thinking of writing up a super slimmed down guide to getting everything setup.
  • After the server setup, grabbing the subdomain is really easy with Ruby on Rails. I've got this in my ApplicationController:

before_filter { |c| c.subdomain = c.request.subdomains.first }

def subdomain=(value)
@subdomain = value
end

def subdomain
@subdomain
end

I just do my lookup for the user's account with, "subdomain", and it works!
  • Tests are your friend. The controllers that had a descent amount of functional tests (unit tests for controllers) were easy to get working with the new URL scheme - those without were a BEAR! I ended up writing a few tests along the way, which is always a good thing. But the funny thing is, the last bug I fixed was solved by accidentally looking at the command line output of the web server while I was trying to use the app in a browser.
  • Routing and code simplier. Removing, "company/yourcompanyname", from the front of the URL has made my Ruby on Rails routing file a helluvalot simpler! I did a little bit of refactoring with this change, and my URL's in general are easier to work with.

Speaking of refactoring... There is a bunch of refactoring I'd love to do with the code base of this application. This is my first Ruby on Rails app!
Overall, I'm very very very happy I made this change. I think it gives Pudding a more professional feel. It only took 2 working sessions to get everything going (I'm not counting the first session where I read up on HowToUseSubdomainsAsAccountKeys).

Labels: , ,