Creating Dynamic Web Sites with Ruby on Rails

Creating Dynamic Web Sites with Ruby on Rails
Page content

Create a blog in 15 minutes! No doubt you’ve heard this before. I’m willing to wager, however, that when you’ve heard this before, the context was populating a blog with your content. And if you’ve ever tried it, you know that this is feasible. Here, though, the context is different. As here, I’m referring to creating a blog application, from scratch, in 15 minutes. Such is the claim made by Ruby on Rails. And guess what, Ruby on Rails actually delivers! And not just for blog applications, as numerous other applications can be developed efficiently with Ruby on Rails.

Overview of Ruby on Rails

How does Ruby on Rails make good on seemingly outlandish claims? This Web framework, based on the Ruby programming language, makes various assumptions on behalf of the Web developer:

“Rails is opinionated software. That is, it assumes that there is a best way to do things, and it’s designed to encourage that best way - and in some cases discourage alternatives. If you learn ‘The Rails Way’ you’ll probably discover a tremendous increase in productivity. If you persist in bringing old habits from other languages to your Rails development, and trying to use patterns you learned elsewhere, you may have a less happy experience.”

(Source: What is Rails? Getting Started with Rails)

The guiding principles for Ruby on Rails also convey the effectiveness derived:

  • DRY - Don’t Repeat Yourself. In other words, avoiding repeating code.
  • Convention over Configuration - Accept the “The Rails Way” (i.e., the assumptions made on your behalf) and get on with it!
  • RIP - Be RESTful in Patterning. Ruby on Rails asserts that REST (Representational State Transfer) is the best pattern for Web applications, as organizing applications around resources and standard HTTP verbs is highly effective.

Fundamental to Ruby on Rails, the Model-View-Controller (MVC) architecture tangibly illustrates how the above assumptions and principles are put into practice:

  • Models - In Ruby on Rails, models represent application data - and the rules to manipulate that data. Because database interaction remains a focal point for Ruby on Rails, models are used for interaction with tables in a database. Because business logic tends to be concentrated in models, Ruby on Rails offers isolation from the user interface.
  • Views - In contrast to Models, Views represent the application’s user interface. With a focus then on presentation, Views are typically HTML files embedded with Ruby code.
  • Controllers - Described as the glue between Models and Views, Controllers mediate interactions between the same.

Theory aside, Ruby on Rails comes with a number of components to accelerate the development of Web applications. Broadly speaking, these components provide a ready-to-use implementation of the MVC architecture by leveraging and extending Ruby.

Getting Started with Ruby on Rails

It’s surprisingly easy to get started with Ruby on Rails. Why? For one reason or another, many operating systems have Ruby pre-installed. (Even if it isn’t, not to worry, as Ruby is easily installed.) To a base installation of Ruby, you need to add the RubyGems package manager. And once you have RubyGems, installing the Rails framework is relatively easy. In addition to Ruby, RubyGems, and the Rails framework, you’ll need a database and a Web server. (Specifics for all of this are covered in detail elsewhere.)

Armed with the Ruby on Rails development environment, you can get started on building that first application - perhaps the blog application referred to at the outset. Whether your preference is for traditional print texts or online media, you’ll be well served by the multitude of resources available. And although the Rails mothership is a terrific resource and starting point, Ruby on Rails content can be found in numerous other places (e.g., Dev Articles). This latter point underlines the Open Source impact of Ruby on Rails and the vibrant community and ecosystem that has developed. (Ruby on Rails is released under the MIT License, whereas Ruby is released under the Ruby License.) Initiated in 2003 by David Heinemeier Hansson, Ruby on Rails has witnessed significant adoption due to the impressive results it delivers consistently and efficiently. Despite its success, Ruby on Rails remains a work in progress with plenty of opportunity for involvement.