April 16, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Ruby on Rails: All Aboard the Fast Train to Web Application Development

  • December 7, 2006
  • By Dominic Da Silva
  • Send Email »
  • More Articles »

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.

Installing Ruby

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:

C:ROR>rails myfirstrailsapp
       create
       create app/controllers
       create app/helpers
       create app/models
       create app/views/layouts
       create config/environments
       create components
       create db
       create doc
       create lib
       create lib/tasks
       create log
       create public/images
       create public/javascripts
       create public/stylesheets
       create script/performance
       create script/process
       create test/fixtures
       create test/functional
       create test/integration
       create test/mocks/development
       create test/mocks/test
       create test/unit
       create vendor
       create vendor/plugins
       create tmp/sessions
       create tmp/sockets
       create tmp/cache
       create Rakefile
       create README
       create app/controllers/application.rb
       create app/helpers/application_helper.rb
       create test/test_helper.rb
       create config/database.yml
       create config/routes.rb
       create public/.htaccess
       create config/boot.rb
       create config/environment.rb
       create config/environments/production.rb
       create config/environments/development.rb
       create config/environments/test.rb
       create script/about
       create script/breakpointer
       create script/console
       create script/destroy
       create script/generate
       create script/performance/benchmarker
       create script/performance/profiler
       create script/process/reaper
       create script/process/spawner
       create script/runner
       create script/server
       create script/plugin
       create public/dispatch.rb
       create public/dispatch.cgi
       create public/dispatch.fcgi
       create public/404.html
       create public/500.html
       create public/index.html
       create public/favicon.ico
       create public/robots.txt
       create public/images/rails.png
       create public/javascripts/prototype.js
       create public/javascripts/effects.js
       create public/javascripts/dragdrop.js
       create public/javascripts/controls.js
       create public/javascripts/application.js
       create doc/README_FOR_APP
       create log/server.log
       create log/production.log
       create log/development.log
       create log/test.log

C:ROR>




Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel