Server-Side Magazine

An Introduction to Ruby on Rails

The use of web application frameworks by developers has gained a significant market share in the last few years.

These frameworks allow developers to significantly increase their productivity by minimizing the amount of time they spend writing and compiling code. One of the preferred and most exciting web application frameworks in use today is Ruby on Rails, also known simply as Rails or RoR.

History

Publicly released in 1995, the Ruby language was developed by Yukihiro Matsumoto, nicknamed Matz, to carefully balance functional and imperative programming. When his search for a scripting language “more powerful than Perl and more object-oriented than Python” turned up nothing suitable, Matz constructed Ruby so everything is an object. Since the rules that apply to objects apply to everything in Ruby, the new user has no exceptions to remember.

Software frameworks provide the scaffolding developers use to support their code. Function libraries, project templates, and layers for database access are a few of the components a framework might provide. Danish programmer David Heinemeier Hansson extracted what became the Rails framework from his work on the project management tool Basecamp and chose Ruby as its language.

Released as open source in 2004, Rails allows rapid development and deployment of web programs by providing a solid consistent infrastructure. This allows developers to focus on the unique features of the software they are creating instead of worrying about the underlying architecture.

Ruby on Rails is, as mentioned, an open source framework written in the Ruby programming language. Development of RoR has quickly grown since its release in 2004. The current RoR version at this writing is 3.0. The underlying architecture of Rails consists of a Model-View-Controller approach pattern of development.

The current output options of a Rails application are HTML or XML; although the final number of lines of code is negligible when compared to other frameworks. The popularity of RoR is undeniable: its usage is estimated at over 200,000 websites, and about 2% of the most visited websites take advantage of the Rails framework as their enterprise solution. Organizations such as Amazon, NASA, the British Broadcasting Corporation, IBM, and Cisco have implemented Rails for their websites.

Overview

In another simplification over existing object-oriented languages, Ruby supports only single-level inheritance. Collections of methods, called modules and referred to as categories in Objective-C, can be included into a Ruby class. This technique, known as a mixin, gives the user the flexibility of multiple inheritance without needless complexity or restriction. Ruby is a powerful tool with a short learning curve.

Ruby is a highly portable language, running on many versions of Linux/UNIX, OS/2, Windows 95 through Windows 7, Mac OS X, and even DOS. The language offers threading independent of the operating system, so multi-threaded applications can be written for systems that don’t have native support.

One of the reasons Rails is growing in popularity among developers is that it delivers certain assumptions about how web development has come along over the last few years. The philosophy behind Ruby on Rails is to allow the developer to start seeing results without having to resort to long configuration files or redundant writing of code.

To this extent, the rails framework presents an orthodox yet effective approach. One special strength of Rails is that it favors meta-programming: the use of existing programs to write new programs. RoR is based on the concept that coding should be breeze, not a burden.

Sample Code

The elegance of Ruby on Rails can be seen in its internal database configuration file. Assuming that SQLite3 is installed, take a look at how RoR allocates a separate database file in each environment for development, testing, and production:

development:

1
2
3
adapter: sqlite3
database: db/development.sqlite3
timeout: 5000

test:

1
2
3
adapter: sqlite3
database: db/test.sqlite3
timeout: 5000

production:

1
2
3
adapter: sqlite3
database: db/production.sqlite3
timeout: 5000

Related Posts

Tags: , , ,

About the Author

Anthony Sparks
Anthony Sparks

He is a web developer and graphics designer for 10 years, specializes in various internet marketing techniques. Currently working for a web hosting company.

Comments

Leave a Comment

Your email address will not be published. Required fields are marked *

Markdown enabled. Click here to see the syntax.

 
More in Ruby (2 of 3 articles)