Ruby on Rails: weapons of mass customisation

by Dafydd Rees

Ruby on Rails is a framework for building web applications. This article describes Ruby on Rails - or just "Rails" as it's also known - and provides some starting points for developers.


What is Ruby on Rails?

image of hands on a laptopRuby on Rails is a "generative framework" meaning that the framework creates a skeleton application for you to customise and extend. This alleviates the need to download a number of different parts, understand exactly how to piece them together and handle a lot of variation in how that could be done. Rather than having a lot of flexibility in terms of how things are put together but a lot of detailed work to do up-front, Rails takes an "opinionated approach" by creating a "ready-to-go" project with a number of pre-configured components. Creating a minimal, working, project is as simple as typing "rails" followed by the name of the project and waiting for all the files and directories to be created.

Ruby on Rails is an "extraction" or what's known as a "harvested framework". This means that the authors wrote a working web application first and then extracted some common code to form a framework. In the case of Rails that original web application was a project management application called "basecamp" (made by 37 signals) which continues to be sold as a web-based service to this day.

From the developer's point of view it's important to remember that the productivity gained from using a framework doesn't come from having a lot of code generated up front by a tool but rather it comes from the fact that a framework is essentially a prefabricated application in a particular style and that you're inserting and configuring new pieces of code within an existing scheme. As a developer you're making an up-front choice to build an application in a certain style and are committing to the scope and limits of that style. Being productive with Ruby on Rails, like any other framework is a matter of understanding how it works, choosing it when the solution fits in with the strengths of Rails and designing within it's conventions and limitations.


How it fits together

When you generate a Ruby on Rails application you get a fully working application complete with a small, embedded sqlite database and a lightweight embedded webserver for development use. Obviously in production we can expect people to want to run other databases and connect through to a web server that can handle a reasonable load. The main configuration settings exist in a subdirectory called "config". The two most important of these are "database.yml" and "routes.rb". The file called "database.yml" configures the database used by your Rails application and "routes.rb" describes how Rail will route web requests back to different parts of your codebase. I have used Ruby on Rails with MySQL and Microsoft SQL Server. Working drivers exist for other databases such as Oracle.


Where to go from here

The real skill of Rails development is learning how to configure and extend the facilities that it offers, rather than just building new things which may or may not fit well with the core framework.

Rails is a popular platform with many freely available on-line resources.The best known tutorial book is "Agile Development with Ruby on Rails". It presents a sample application and takes the reader through a number of development stages adding features as it goes. It's advantageous that this book is available as a PDF as well as in print, making it searchable and easy to carry around.

The most important thing to note about Rails documentation is that Ruby and Rails are both undergoing a series of rapid changes as they mature. It's important to try out what you read rather than just accepting it as a lot of the "how to" literature is out of date.

In the rush to develop new web applications, many people neglect the Ruby programming language itself, preferring to rely on the canned functionality of the Rails framework. This is a false economy as you can't understand Rails or any of the Rails plugins without a reasonable grasp of the language. Most commercial programmers (especially those from a C++, Java or C# background) aren't familiar with the dynamically typed object-oriented approach taken by Ruby so it's important to spend some time learning the language itself rather than just following Rails "howto" documentation. The book "Programming Ruby" by the Pragmatic Programmers, although popular is verbose and overly long. It's especially annoying that about half of the 803 page book is simply a less current version of the API documentation that's freely available on the web. Including that material just means the book goes out of date sooner and that it's more cumbersome to carry around. I recommend Flanagan and Matsumoto's book "The Ruby Programming Language" instead because it's well-organised and far more concise.

The "railscasts" video podcasts are a series of mini-tutorials that explain a concept or show you how to do something by video. The "railscasts" video podcasts are free whereas there are additional paid-for mini-tutorials under the name "peepcode". Both can be quite effective for learning a new technique.


Conclusion

Most people moving from Java or .Net to Rails development experience a substantial productivity gain however it's worth noting that there's a large amount of learning to do. Being productive with Rails is a matter of choosing it for projects that can live within it's conventions and limitations and make the most of it's strengths.



References and Links
The Ruby on Rails Framework, www.rubyonrails.org
Railscasts, railscasts.com - Freely downloadable rails-related video tutorials
Flanagan and Matsumoto, The Ruby Programming Language, January 2008, O'Reilly, ISBN 0-596-51617-7
Thomas and Hansson, Agile Development with Ruby on Rails, Second edition, 2007, Pragmatic Programmers, ISBN 0-9776166-3-0



About the Author
Dafydd Rees is a software developer specialising in object-technology and agile methods. He welcomes feedback on this article at www.dafydd.net/feedback.php.



Send a comment about this article to editor@itwales.com.



Menu: Home, Services, Events, Features, Interviews, Profiles, Reviews, News, Resources, Press