Ruby on Rails Quick Start

Rails

Introduction

Ruby on Rails is a web framework built on top of the Ruby programming language that focuses on convention over configuration to get things done. It was originally developed by David Heinemeier Hansson at 37signals for the Basecamp application. Eventually, the framework was extracted from Basecamp, open sourced, and is now known as Ruby on Rails. It is also a total pleasure to work with.

Requirements

It is assumed that you have knowledge of the Ruby language and a working development environment in order to make use of this post. Read my Intro to Ruby article series if you need further instruction.

Literature

  1. Build Your Own Ruby on Rails Web Applications by Patrick Lenz - This was the first book that I read on the Rails framework that walks you through building a simple web application from start to finish. Something to consider but you might enjoy the book listed below better.
  2. Agile Web Development with Rails, Third Edition - Have not read this book myself as of yet but have heard very good things about it.
  3. RESTful Rails - A free PDF available for download. While knowing the REST architecture is not a prerequisite to developing Ruby on Rails applications, I would strongly recommend that you take time to understand how to use it. You’ll be glad you did.

API

Good bookmarks to have on hand are:

  • API Doc - Provides quick keyword search capabilities as well as community comments for Ruby and Ruby on Rails. My personal favorite.
  • Got API - An alternative to API Doc but not as easy on the eyes. Depends on your temperament, of course.

News

The following feeds are worth adding to your feed reader in order to stay connected with the community:

Tools

Using a simple text editor like TextEdit (MacOS) or Notepad (Windows) will do just fine for starters. However, you might consider the following tools as better alternatives to simple text editors:

  • TextMate - Lightweight, fast, and costs $30. For the MacOS platform only.
  • NetBeans - Developed by Sun and free to use. Works on multiple platforms.
  • Aptana - Adds Ruby on Rails support to the Eclipse IDE. Visit the software update site to install directly into Eclipse.

I am a MacOS guy, so TextMate is my development tool of choice when writing Ruby code. However, if you are not on the MacOS I would recommend Netbeans as it is less buggy than Eclipse (although I do like the Eclipse UI better).

In addition to the tools mentioned above, you might consider installing the SQLite Manager Firefox add-on for quick and easy access to your SQLite3 database. You can find this and other recommended plugins for Firefox on my Firefox page.

Installation

Installation and setup is as simple as installing a few Ruby gems. Execute the following commands from a command line in the following order:

  1. sudo gem install rails
  2. sudo gem install mongrel
  3. sudo gem install sqlite3-ruby

When you generate a rails app it will default to using the SQLite3 database. Feel free to install MySQL or some other database for your development needs. The Mongrel gem installs a web server stack for running your Rails application. By default, you can run Rails on WEBrick but I recommend using Mongrel instead.

Creating a Rails App

To create your first Rails app, open a terminal window in a working directory of your choice. Then execute the following command:

rails MySpiffyApp

This will create a new folder in your working directory called “MySpiffyApp”. Inside this directory you will have set of files and folders that represent the default Rails web application structure. Make sure to read the README file located in the root of “MySpiffyApp” directory to make sense of the file and folder structure.

Running Your Rails App

Right, so now you have a Rails app but how do you run it? While still in your terminal window, change to the root of your Example project folder and type:

script/server -u

This will launch your Rails app with debugger support enabled (i.e. the “-u” option). To view your app, just plug this address in your web browser: http://localhost:3000

Congratulations, you have successfully installed Rails, built a Rails app, and seen it running!

Next Steps

I will be releasing various bits of code in the future that will make building your Ruby on Rails apps easier. Stay tuned if you want to learn more and don’t be afraid to send me some feedback as comments are always welcome.

Tags:

Monday, March 9th, 2009 Software

No comments yet.

Leave a comment

You must be logged in to post a comment.