Ruby on Rails
I’ve been meaning to learn Ruby for a long time. It’s built a reputation as a language that you can build programs with incredibly quickly, so I wanted to add it to my skillset. The best way to learn a new language is to actually use it to do something, but as Mike Loukides points out it’s awfully hard to do it when you need the problem solved now.
The first program I was going to write to learn Ruby was a resume generator. It was supposed to take a resume, in XML, and generate either a LaTeX, HTML or Word version. That was two and a half year ago. Shortly after I started, I got a job, and hence the need dropped dramatically.
Recently Ruby on Rails has appeared on the scene. It’s supposed to take Ruby’s speed of development and elegence to web application development. O’Reilly has written a tutorial for Rails, so I took this opportunity to pick up Ruby again.
At the end of the tutorial I hadn’t actually learned that much Ruby, but enough to get going. And I have a copy of Programming Ruby if there’s something I can’t figure out.
The beauty of Rails is the amount of automation it does for you. Once you have a data model everything else can be generated and you can be editing objects almost immediately. The real question is it as useful as people make it out to be? Even in the simplistic tutorial you had to override some scaffolding methods and write a few custom pages to get the functionality beyond just directly editing objects.
A quick side note about PostgreSQL. The tutorial uses MySQL and some GUI tool to make the data model. This is overkill for me and I just wrote the SQL straight. But Rails (or more specifically ActiveRecord) requires an implicit sequence to exist for each object type. Basically each table that holds an object type requires a column called ‘id’ with type ’serial’. On table creation a sequence called ‘tablename_id_seq’ is also generated, Rails needs that sequence. This took me a long time to figure out because in the past I always maintained sequences manually. This ensured that each object in my database had a unique ID. The first thing that jumped to my mind was that you can’t do inheritance with ActiveRecords because IDs will be duplicated across object types.
The rest of the tutorial shows the basics of mixing objects, e.g. assigning a receipe to a category.
My current impression is Rails makes it easy to quickly prototype ideas but would take significantly longer to write a production ready app. As far as I can see you will need to rewrite the controllers and web pages, add on top of this validation, styling, error pages, etc. I don’t know how much quicker it will be.
So to find out if right or wrong I’m putting together a small web application to manage a golf league I’m in. It’s simple enough but there are plenty of has_many, has_one, belongs_to relationships to make it more complicated. Add in authentication and automatically using the logged in user to control who a score belong to (instead of going to /user/edit/3), etc. and it’s beginning to get complicated. I’m curious if the automated URL mapping and scaffold methods will be useful or if they will get in the way.
I’ve already got my data model and found a recent addition to Rails that adds support for users and authentication so hopefully I should have something up and running together pretty soon.

March 27th, 2005 at 10:42 am
This is qutie a good intermediate introduction to get you to the next level in Rails after the o’reilly tutorial: http://rails.homelinux.org/