By Jake Edge
December 19, 2007
Rails (aka Ruby on Rails
or RoR) is a framework for building web applications. It has gotten
a lot of attention – some would say hype – over the past few years as easy to
use and learn, while allowing the creation of complex database-backed web
services. In the year since Rails 1.2, the team has not been idle, with
their work culminating in
the release of Rails 2.0 this month.
RoR is based around the idea of using the model-view-controller (MVC)
pattern to cleanly separate the user interface from the
application logic and data storage. All of the Ruby code written or
generated for a
Rails application is organized into a directory hierarchy based on what
part of the MVC they implement. All of the parts of the application know
how to find the others because of this convention, which is in keeping with the two principles
that guided the development of RoR.
Fundamentally, RoR is built around two principles. The first is "convention over
configuration", which is the idea that only things that deviate
from standard practices need to be specified via configuration. One can
get surprisingly far by sticking with these standard practices. The other
principle is "don't repeat yourself", which means that there is a
single place to go to specify something about the application; other places
that need it or things derived from it, retrieve it from the canonical
place. This is most evident in the specification of database
table and column names; they are described in the model and other parts of
the application retrieve them as required.
The principles are interrelated, of course, and are two of the innovations
that RoR has popularized for web application frameworks. Many previous
attempts required a huge amount of configuration information to be
specified, often nearly identically in multiple places. Simplifying this
configuration headache was explicitly a goal for Rails. It can take a bit
of time to come to grips with the conventions used, but once that is done
it is straightforward to use the framework.
Generating code to handle simple modifications to the database data, known
as scaffolding, is another technique popularized by RoR. From the
specification of the data model, Rails will generate an interface to
create, read, update, and delete data in that model. It can also generate
"migrations" which contain
the SQL necessary to create or modify the database tables to reflect
changes in the model. Migrations can be used in both a forward and
backward direction to keep the
database in sync with the state of the application as changes are made.
Rails itself is broken up into multiple components implementing each piece
of the MVC architecture: ActiveRecord for the model, ActionPack for the
view and controller, along with a number of lesser players. It provides
extensive test harness facilities that allow testing of the web application
without using a browser or network at all. RoR is a comprehensive
solution, with a large number of very vocal supporters.
The new release provides a number of new features, some performance
enhancements, as well as the requisite bug fixes. The bulk of the changes
in 2.0 are in the controllers. The first is better support for "representational
state transfer" (REST) style web application APIs, which were introduced in
Rails 1.2. Better support for multiple different views based on
application criteria were also added, allowing the interface to change
based on the device accessing it, for example.
Security enhancements were made as well, with code being added to help protect against
cross-site scripting and cross-site request forgery attacks. These two
web application flaws are becoming rather popular to exploit, so any
assistance a web framework can give is welcome. The default session
objects have changed to be cookie-based, rather than stored in a file or
the database. This allows snooping of the session data, but the data is
hashed to prevent forgery.
Performance and scalability have been the traditional knocks against Rails,
and though there were some enhancements, especially to ActiveRecord, that
should provide some boost, it is not clear how well Rails handles huge
sites. It is something the Rails team is aware of, so, over time,
those kinds of problems should be solved. RoR is a very capable framework
and the 2.0 release looks very good. The Rails community should find much
of use.
(
Log in to post comments)