Rolling with Ruby on Rails
by Curt Hibbs01/20/2005
Maybe you've heard about Ruby on Rails, the super productive new way to develop web applications, and you'd like to give it a try, but you don't know anything about Ruby or Rails. This article steps through the development of a web application using Rails. It won't teach you how to program in Ruby, but if you already know another object-oriented programming language, you should have no problem following along (and at the end you can find links on learning Ruby).
Let's answer a couple of burning questions before rolling up our sleeves to build a web application!
What is Ruby?
Ruby is a pure object-oriented programming language with a super clean syntax that makes programming elegant and fun. Ruby successfully combines Smalltalk's conceptual elegance, Python's ease of use and learning, and Perl's pragmatism. Ruby originated in Japan in the early 1990s, and has started to become popular worldwide in the past few years as more English language books and documentation have become available.
What is Rails?
Rails is an open source Ruby framework for developing database-backed web applications. What's special about that? There are dozens of frameworks out there and most of them have been around much longer than Rails. Why should you care about yet another framework?
What would you think if I told you that you could develop a web application at least ten times faster with Rails than you could with a typical Java framework? You can--without making any sacrifices in the quality of your application! How is this possible?
Part of the answer is in the Ruby programming language. Many things that are very simple to do in Ruby are not even possible in most other languages. Rails takes full advantage of this. The rest of the answer is in two of Rail's guiding principles: less software and convention over configuration.
Less software means you write fewer lines of code to implement your application. Keeping your code small means faster development and fewer bugs, which makes your code easier to understand, maintain, and enhance. Very shortly, you will see how Rails cuts your code burden.
Convention over configuration means an end to verbose XML configuration files--there aren't any in Rails! Instead of configuration files, a Rails application uses a few simple programming conventions that allow it to figure out everything through reflection and discovery. Your application code and your running database already contain everything that Rails needs to know!
Seeing is Believing
We developers often hear the excessive hype that always seems to accompany something new. I can just imagine that skeptical look on your face as you hear my dubious claims. Ten times faster development, indeed!
Editor's Note: Bill Walton has ported this tutorial to Rolling with Ruby on InstantRails -- for a very quick installation experience.
I'm not asking you to accept this on blind faith. I'll show you how to prove it to yourself. First, I'll install the needed software. Then I will lead you through the development of a web application.
Installing the Software
We'll develop this web application on Windows. You can still follow along if you use a Linux or Macintosh system, but your screen will look different from the screen shots shown below and you will have to install software packages built specifically for your system. See the Resources section at end of this article for additional software links.
To develop this web application, install the following software:
- Ruby
- The Rails framework
- The MySQL database (and the MySQL-Front GUI client)
Step 1: Install Ruby

Figure 1. Ruby Windows installer
Installing Ruby couldn't be any simpler:
- Download the latest One-Click
Ruby Installer for Windows (shown in Figure 1). As of this writing, the
latest is
ruby182-14.exe). - Double-click on the downloaded executable and follow the installation
instructions. Unless you have some special needs, just press
Enterto accept all of the defaults.
Note to Linux and OS X users: The Windows installer come with the RubyGems package manager already installed. Whatever means you use to install Ruby, you will probably have to install RubyGems, also.
Step 2: Install Rails

Figure 2. Installing Rails through RubyGems
Now we can use the RubyGems package manager to download and install Rails 0.9.4 (the version covered by this tutorial), as Figure 2 shows:
- Open a command window and run the command
gem install rails --remote. - RubyGems will also install all of the other libraries that Rails depends on. For each of these dependencies, RubyGems will ask you if you want to install it. Answer "y" (yes) to each one.
Step 3: Install MySQL

Figure 3. MySQL Server setup wizard
We still need to install our database server. Rails supports many different databases. We'll use MySQL.
- Download the latest "essential" version of the MySQL Windows
installer. (Currently, that is
Windows Essentials (x86) 4.1.7.) - Double-click on the installer (Figure 3) and accept all of the defaults, though skip signing up for a mysql.com account.
- When you reach the final panel of the installer, clicking the Finish button will bring up the configuration wizard.
- In the configuration wizard, you can also just accept all of the defaults, except that in the security panel you must uncheck the "Modify Security Settings" checkbox (Figure 4). This is because starting with version 4.1.7, MySQL uses a new authentication algorithm that is not compatible with older client software, including the current version of Rails. By unchecking this box, you can access MySQL without a password.

Figure 4. MySQL configuration wizard
Step 4: Install MySQL-Front
MySQL-Front is a graphical interface for the MySQL database. It is an inexpensive commercial application, but you can try it for free for 30 days. In this article, we will use MySQL-Front to develop our database. If you prefer, you can also just send SQL commands to the database from the command line.
- Download the latest version of MySQL-Front (currently, version 3.1).
- Double-click on the downloaded executable and follow the installation instructions (Figure 5). Unless you have some special needs, you can accept all of the defaults.

Figure 5. MySQL-Front installer
![]() |
Essential Reading Building Tag Clouds in Perl and PHP Tag clouds are everywhere on the web these days. First popularized by the web sites Flickr, Technorati, and del.icio.us, these amorphous clumps of words now appear on a slew of web sites as visual evidence of their membership in the elite corps of "Web 2.0." This PDF analyzes what is and isn't a tag cloud, offers design tips for using them effectively, and then goes on to show how to collect tags and display them in the tag cloud format. Scripts are provided in Perl and PHP. Yes, some have said tag clouds are a fad. But as you will see, tag clouds, when used properly, have real merits. More importantly, the skills you learn in making your own tag clouds enable you to make other interesting kinds of interfaces that will outlast the mercurial fads of this year or the next. Read Online--Safari Search this book on Safari: |
Related Articles:
Bringing Ruby on Rails with FastCGI into Mac OS X Server
Most of the Ruby on Rails documentation on deployment for Mac OS X glosses over key parts of the plumbing. In this article, Luke Burton walks you through a Rails installation on Mac OS X Server.
Hacking Asterisk and Rails with RAGI
RAGI combines Asterisk's VoIP handling capabilities with the power and efficiency of Ruby on Rails. Joe Heitzeberg will lead a tutorial using his bindings for Asterisk with the Ruby on Rails framework at the Emerging Telephony conference.
What Is Ruby on Rails
Ruby on Rails is an impressive web development framework that will soon reach version 1.0. While there's a lot of buzz, it can sometimes be difficult to discern the steak beneath the sizzle. Curt Hibbs walks through the features and pieces of Ruby on Rails to show how it fits together and where its big benefits come from.
Ruby on Rails: An Interview with David Heinemeier Hansson
Few can have missed the rise of the programming world's latest star
platform--Ruby on Rails. Rails'
creator, David Heinemeier Hansson,
already wowed the crowds at this year's OSCON, and is set to keynote the European O'Reilly Open
Source Convention in Amsterdam this October.
O'Reilly Network talked with him
about Rails' success and future.
Ajax on Rails
XMLHttpRequest and Ruby on Rails are two hot topics in web development. As you ought to expect by now, they work really well together. Curt Hibbs explains the minimal Ajax you need to know and the minimal Ruby you need to write to Ajax-ify your Rails applications.
Rolling with Ruby on Rails, Part 2
Curt Hibbs introduced Ruby on Rails by building a simple but functional web application in just a few minutes. Does the ease of use continue? He thinks so. In the second of two parts, Curt completes his example Rails application in merely 47 lines of code.






