Ruby on Rails: All Aboard the Fast Train to Web Application Development
Ruby is the programming language on the tip of everyone's tongue these days. The power and ease of software development with Ruby has helped make an upstart web framework called Ruby on Rails the hottest web framework around. Some may argue that the Web 2.0 wave is riding the Rails on Rails wave, as more and more Ruby on Rails powered web sites pop up on the internet.
This article will give a brief introduction to Ruby on Rails and show you how to get your first simple Ruby on Rails web application up and running. In Part 2 of this article, you will connect your web application to the MySQL database and add CRUD (Create, Read, Update, and Delete) support to the web application.
Ruby: A Scripting Language Gem
It is hard to imagine anyone in the programming world these days who has not heard of Ruby. The ever-increasing popularity of the Ruby on Rails web framework is helping to make Ruby the language of choice for rapid application development and testing. Ruby is an interpreted scripting language that provides quick and easy object-oriented programming and contains some neat features such as closures, blocks, and mixins. Ruby is also highly portable, running on Unix/Linux, Windows, and MacOS. For those wanting a more thorough introduction to Ruby, you can read W. Jason Gilmore's article on Ruby.
Rails: The fast Train to Web Application Development
Ruby on Rails was created by David Heinemeier Hansson, a partner of 37 signals, as a web application framework for building their web applications. David open sourced Ruby on Rails under the MIT license and it is now the fastest-growing web application framework. It is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern. It provides Ajax support in the view layer, a request and response controller, and a domain model wrapping the database. All that is needed to deploy a Rails web application is a web server and a database. In this article, you will download and install Ruby, the Rails framework, and MySQL so you can run your very first Ruby on Rails web application.
Ruby runs on Window, Unix, Linux, and MacOS operating systems. This article will assume an installation of Ruby on Rails for a Windows-based operating system. The fastest way to Ruby up and running is to download the One-Click Ruby Installer for Windows. This is a one-click, self-contained installer that contains the Ruby language as well as dozens of popular extensions and packages, and editor and execution environment. Download the latest version, 1.8.5-21, and double-click the ruby185-21.exe executable, following the installation instructions to install Ruby.
Installing the Rails Framework
The one-click Ruby installer also installs RubyGems, the Ruby package manager. You can use RubyGems to download and install Ruby on Rails. Open a command prompt and run the following command:
C:>gem install rails --remote
RubyGems will also download and install other libraries that Rails depends on. When prompted to install each of these, answer 'y'. Once RubyGems is complete you will have Rails version 1.1.6 installed:
C:>rails .v Rails 1.1.6
Installing the MySQL Database
MySQL is the most popular open source database available. The latest version of the MySQL Community Server is version 5.0. You can download the MySQL 5.0 Community Server Windows Essentials (x86) installer. Double-click the installer and follow the installation instructions, accepting all defaults. Click the 'Finish' button on the final panel, and uncheck the 'Modify Security Settings' checkbox; this will allow you to access MySQL without a password. If you are not comfortable administering MySQL from the command line, you will want to download a graphical front-end client for MySQL. A good MySQL front-end application is HeidiSQL and you should download and install it so you can administer your MySQL database.
Running Your First Ruby on Rails Web Application
Now that you have Ruby, Rails, and MySQL installed, you can create your first Rails web application. In addition to a runtime web application framework, Rails contains a set of helper scripts that are used to automate tasks when developing your web application. The first script you will need is the one that creates your web application template (directory structure and initial set of files). From a command window, go to the directory that you want your web application to live in and type the following:
Page 1 of 2