Ruby on Rails: First contact

rails_logo_remix.gifToday I finally decided to dive a little into Ruby on Rails. I have a cool, small and fun application in mind and wanted to see whether it’s true that Rails is so much more productive that I could develop it in my very little free time.

Being on OS X Tiger, first of all I had to fix Ruby following these instructions. Then, to make things easier, I decided to download and install Locomotive. I started Rails, generated a simple controller and wrote my first “Hello world” webapp. So far, so good.

My first attempt to generate a scaffold didn’t go too well. Looks like there’s a bug in Rails 0.14.1, the version included in Locomotive. I applied this patch and everything was fine again.

From here, the plot started to thicken. The table for which I wanted to generate a scaffold had a few fields named xx_count and these columns were not mapped by ActiveRecord. By sheer luck, and after some head scratching, I guessed that it didn’t like the column names. I changed them to xx_cnt and it worked! Go figure.

I am also accustomed to putting an integer field named id in my tables and to use it as a primary key. Fortunately, this is exactly the type of pattern that Rails is most happy with. The only problem is that, being a hater of MySQL, I configured Rails to connnect to my PostgreSQL 8 server from the start (Locomotive supports MySQL, PostgreSQL and SQLite out of the box). Since Rails wants the id field to be auto-incremented by the database and PostgreSQL does not support the serial column type, I got some cryptic errors upon trying to save a new record. The messages could have been much more explicit, but I could have figured it out earlier, had not my clarity of vision been obfuscated by a long work day.

Anyway, Google to the rescue, I worked around this problem following the suggestion outlined here, and I was finally able to get a basic CRUD application working. Next time, I’ll try to start implementing some more realistic use case. To be honest, I haven’t yet figured out the details of how my app is supposed to work and look like. I think I’ll just code away and see what comes out of it, testing various solutions along the way and seeing what sticks. I hope that, with Rails’ purported high productivity, I won’t regret too much ending in a cul-de-sac and having to start over again. I’m mostly doing this for fun and for learning, so errors are a good, actually.

3 Responses to “Ruby on Rails: First contact”


  1. 1 Brian McCallister

    Umh, postgres does serial…

    brianm=# create table foo (id serial primary key);
    NOTICE: CREATE TABLE will create implicit sequence “foo_id_seq” for serial column “foo.id”
    NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index “foo_pkey” for table “foo”
    CREATE TABLE
    brianm=#

    Weird =/

  2. 2 Tracy

    I was thinking that when I read it, that pgsql did doe serial. I was doing the O’Reilly tutorials in PostgreSQL instead of MySQL and used serial.

  3. 3 Simon Harris

    Ditto. I use serial in postgres all the time without a problem.

    I don’t know what I’d do without postgres. MySQL truly sux ass. It’s slow. Bloated. I’m always bemused when a “relational” database doesn’t support referential integrity _properly_.

Leave a Reply