Getting your feet wet with Ruby on Rails

Ruby on Rails logo

This article doesn’t teach you a lot about Ruby or Rails, but the nice part about it is that it shows you how easy it is to build web apps with Rails.

I went through his tutorial last night and looked at my watch before and after. Literally, it took only 20 minutes to build a MySQL-backed bookmark storage application and I spent a good chunk of that time trying to figure out why it wasn’t working for me at first (contrary to what the article advises, I had to launch the WEBrick server while in the “Bookmarker” directory) and trying to analyze what was going on behind the scenes. Pretty impressive that you can build an app that fast and without writing a lot of tedious “glue” code

Here’s a brief summary of the steps:

  1. Create a database (I used MySQL) and a table. Rails wants you to create a table for whatever object you’re trying to store with a plural name (e.g.: “bookmarks”) and wants it to have an auto-incremented integer primary key called “id”.
  2. Execute rails <app_name> to have Rails generate a directory for your application with 11 subdirectories and lots of files already filled-in for you.
  3. Edit config/database.yml to point to your database.
  4. Execute ruby script/generate scaffold <model_name> to generate a bunch of code that handles New, Show, Edit, and Destroy operations. model_name is your database table but with a capital letter and not plural (e.g.: “Bookmark”), which I found to be weird and inconsistent.
  5. Execute ruby script/server to fire up a WEBrick server on port 3000. It logs to stdout so it’s very easy to see your errors.
  6. Point your browser at http://localhost:3000/<controller_name> and observe that you have a working application! (controller_name is like your database table, lowercase and plural – e.g.: “bookmarks”).
  7. Customize and extend the pre-generated code in the app directory. Ruby code has a .rb extension and HTML templates have a .rhtml extension and live in app/views.


Books on Ruby on Rails from

Agile Web Development with Rails : A Pragmatic Guide (The Facets of Ruby Series)Rails RecipesProgramming Ruby: The Pragmatic Programmers\' Guide, Second Edition

2 thoughts on “Getting your feet wet with Ruby on Rails

  1. The following article does an interesting comparision of PHP vs. Ruby on Rails and PHP wins for him.

    The author doesn’t seem to have as much of a problem with Ruby or Ruby on Rails as he does with the general concept of MVC frameworks. His beef is that they work well for simple CRUD apps but then become untenable when you start working on more complicated apps with SQL queries with joins and such. An interesting point. I don’t know if Rails or other MVC frameworks have ways of dealing with this.

    The comments are interesting. Another interesting thing is that people seem to mostly be concentrating on two-tier apps, where the server code accesses the database directly. These apps tend to be simpler which means that they can easily be written in straight PHP but they also can easily be achieved with something like Rails, which wraps the database with an object layer. The stuff that people do in J2EE tends to be three-tier architectures where there’s a layer of business objects and business logic on top of the database. Perhaps Rails would be a bigger win in this type of situation?

  2. Now that I had been through the process once before and worked out the kinks, a colleague and I decided to build another simple web app that we had been wanting for internal project tracking. Start to finish, it took 5 minutes this time.

    I wonder how well Ruby on Rails works for more complex applications…

Leave a Reply

Your email address will not be published.