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:

Kinda ghetto!

The URL will now look like this:

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 "", 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

def subdomain

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: , ,


Blogger Graeme said...

Thanks, I'm glad the tutorial was useful to you. :-) What was the portion that had you scratching your head? I'd like to improve it so others don't wind up doing the same...

Monday, December 04, 2006 4:21:00 AM  
Blogger mathie said...

Oh, since apparently the link to my profile says it can't be viewed (eh?) it might help if I point out that the 'graeme' is me, the author of the DNS tutorial. :)

Monday, December 04, 2006 4:29:00 AM  
Blogger John Topley said...

Hi Michael,

Who are you using for hosting and are you using RESTful routes?

Monday, December 04, 2006 6:19:00 AM  
Blogger Michael Sica said...

Hi Graeme, thanks for stopping by. I got confused when you said to add the zone to the named.conf file. You don't explicitly say to edit that file. At first I thought you meant to add it to the rndc.conf file. It wasn't until I noticed this line in rndc.conf, "Use with the following in named.conf, adjusting the allow list as needed:", that I realized I should be looking somewhere else.

I'm a unix/server-config retard so that didn't help the situation.

Tuesday, December 05, 2006 8:33:00 PM  
Blogger Michael Sica said...

Hi John, I haven't picked a host yet. I was referring to developing locally. My Rails code is sooooo Rails 1.0 it isn't funny. After I launch I plan on grabbing that new, "Agile Web Development with Rails", book and catching up on RJS and the RESTful/HTTP development style. I saw DHH's presentation on the HTTP style of development and I really liked it. But I don't want to tear up my app when it's so close to completion!

Tuesday, December 05, 2006 8:36:00 PM  
Blogger John Topley said...

Very wise, Michael. It's pretty tough continuously rewriting your app to keep up with Edge Rails!

# Shameless plug
I just put my first (non-profit) Rails app online. It's a simple asset tracker. See

You can sign in using demouser/demouser if you just want to look at it without signing up.

Wednesday, December 06, 2006 4:37:00 AM  
Blogger Michael Sica said...

Hi John, I just checked out your app. Congrats man, it's pretty nice!

Why is it a non-profit service?

Wednesday, December 06, 2006 8:39:00 PM  
Blogger John Topley said...

Thanks Michael! :-)

Never say never, but the main reasons are that I don't have the infrastructure in place yet to support that and also I don't think there's enough value there yet to charge for it. For example, if I were paying for it then I'd want to be able to import data instead of typing it in, but that's quite a hard nut to crack given the variety of export formats out there.

Thursday, December 07, 2006 3:44:00 AM  

Post a Comment

<< Home