I just started learning Ruby On Rails. Since I like to be on the bleeding edge, I decided to go 2.0. What I found was that although there were a lot of tutorials on Rails 1.2, there was hardly anything on 2.0. To make matters worse, just enough had changed to make the tutorials on the web not very helpful to me. Fortunately my good friend Josh Kahn helped walk me through the basics and so I decided to take notes. (Note: this is for a Windows installation.) Yeah, I know, I said I was a Mac guy, but this is for work.

Curt Hibbs has already wrote a good intro to Ruby on Rails and some of the prerequisites to installing Rails, so I won’t rewrite that. Following his lead, I installed:

Installation

  1. Install Ruby using the One-Click Ruby Installer for Windows. (Version 1.8.6-26 as of April 28, 2008).
  2. Install Rails. The Windows installer comes with RubyGems package manager which lets you install the latest version of Rails. Go into the command prompt and run the command
    gem install rails –remote

    Answer ‘y’ to each question.

  3. Install MySQL using the Windows Essentials version. (Version 4.1.22 as of April 28, 2008). Go through the configuration wizard and accept all the settings till you get to Security Settings. Uncheck “Modify Security Settings.”
  4. Install a MySQL front end. I used HeidiSQL, a free open-source one, but there’s no reason you can’t use something else.

The Fun Stuff

This being the web and all, I’m not gonna regurgitate what someone else wrote. I found this pretty easy to follow tutorial by the guy who wrote the ONLamp Ruby on Rails tutorial, but for 2.02. Here’s the Cliff’s notes version for those lazy people like me along with some extra steps that were essential but not covered in the tutorial.

  1. Create a new Rails application called bookstore. In the command prompt, type:
    rails bookstore
  2. Create a scaffold for the bookstore. For this simple example, the bookstore has books with properties title and description. In the command prompt, type:
    ruby script/generate scaffold Book title:string description:text
  3. Configure your database. In your bookstore/config folder, open database.yaml. Your development configuration should look like this:
    development:
      adapter: mysql
      database: bookstore
      host: localhost
      username: root
      password:
      timeout: 5000
  4. Run the database migration script. Now that you’ve configured the database properly, go to the command prompt and type:
    rake db:migrate

    This will create the necessary tables.

  5. Start the server. In your command prompt, navigate to the bookstore directory and type:
    ruby script/server

That’s it. In your browser, navigate to http://127.0.0.1:3000/books/ and you should see your first Ruby On Rails 2.0 app. If you found this post useful, leave a comment. Feedback is appreciated as well.

Popularity: 8% [?]

No related posts.