SKIP TO CONTENT · ACCESSIBILITY · TEXT SIZE: S M L

HOME

News

Getting Started with Ruby on Rails

April 22, 2008 - by Dan Benjamin, A List Apart

You’ve probably heard about Ruby on Rails by now. Your developer friends are raving about it—talking about how they wrote an application in less than half the time it would have taken using some other technology—how they really enjoyed themselves instead of stressing out, and then spent their extra time on the beach. Rails sure does sound like a pretty compelling technology. But what is it, and how does it fit into the big picture of web development?

If you’re a designer, user interface architect, writer, or a software developer not yet acquainted with Rails, you might be wondering what this technology is all about. Can it really cut through the headaches so often associated with web application development? Can it turn you, the mild-mannered non-developer, into a web application programmer overnight? Is Rails really the be-all and end-all development platform? What the heck are Subversion and Git? Do I need to learn all of this just to do design for Rails?

In this article, I’ll help prepare you for your first foray into Rails by explaining what it is, how it works, and where it fits into the spectrum of web development and design. I’ll address the issues above and more, with answers geared toward non-Rails developers, designers, and other creative professionals.

This article isn’t a Rails programming tutorial. We won’t be writing code here, but I will introduce you to some of the important concepts critical to understanding how the Rails framework functions. I’ll also explain what you’ll need to know to work with Rails developers and integrate your XHTML and CSS into Rails projects.

I’ll focus on the topics and issues that I’ve learned are most important for creative people instead of boring you with gruesome technical details. Yes, you’ll have to learn what terms like “MVC” mean, for example, but only in the context of getting stuff done.

What is Rails, and why use it?

David Heinemeier Hansson, a partner at 37signals, created Ruby on Rails. As he built Basecamp, their flagship application, David extracted the application’s underpinnings and created code that he could use and re-use for software he wanted to build down the road.

The framework he created proved to be extensible, expandable, and multi-purpose. He decided to share it as open source software. A small group of developers, now known as the Rails Core Team, formed and improved and expanded the framework. After a good deal of effort, Ruby on Rails matured into a robust, solid software development platform. Today, Rails has a strong community and great documentation, and is used by thousands of developers to power hundreds of websites, such as Twitter, Blinksale, and the very site you’re reading now. There’s an even bigger list of sites over at Working with Rails.

Rails is designed to make building web applications simpler and easier. Rails provides developers with a large, easily expandable set of building blocks they can use (and re-use) to create web applications. Developers can use, integrate, and customize these components of code in any manner they choose to, to create the unique functionality they need for their application. Building software this way really helps reduce the time it takes for developers to create and later maintain their applications. It also helps to standardize the way applications get built, making it easier for many developers to collaborate and write more uniform code.

Web designers have time-tested CSS tricks to use as a starting point, web standards to adhere to, and Photoshop workflows they can rely on. Like these tools, Rails provides standards, conventions, tools, and a foundation upon which developers can construct applications by writing customized code using pre-built Rails libraries.

Rails vs. PHP

One of the questions people often ask about Rails is how it differs from PHP. PHP is a general-purpose scripting language that can be embedded right into HTML pages, making it easy for developers to create dynamically generated web pages quickly and easily. Many web designers and most web developers have used PHP in some capacity. Because of its proliferation (it’s usually installed by default on most webhosts), PHP is often the go-to language for handling simple tasks like keeping your website’s navigation current, randomizing images on a website, and even creating a simple content management system. PHP is also useful for creating full-blown open source and commercial web applications such as WordPress, and HelpSpot, both PHP applications.

Technically speaking, we shouldn’t compare PHP, a programming language, to Rails, a web application framework. Instead, we should compare PHP to the Ruby programming language upon which Rails was built. Ruby was created in 1995 by Yukihiro “Matz” Matsumoto, and has slowly built a following, exploding in popularity and getting more mainstream attention in 2006, in no small part because of the popularity of Rails. At the time of this writing, Ruby ranks as the 9th most popular programming language in the world.

To quote the Ruby website, “Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.” This elegance and focus on simplicity makes Ruby a very approachable language for people new to programming, and offers a refreshing change of pace for seasoned developers.

Let’s run through a quick example, just to get a “feel” for what we’re talking about. Let’s say we want to count from 1 to 10. In PHP, the code might look like this:

for ($i = 1; $i <= 10; $i++) { 
     echo $i;
}

If you’re familiar with C, Java, or other C-like control structures, this is straightforward for you. But if you’re new to this, that might seem pretty intimidating. Here’s the same code in Ruby:

10.times do |i| 
  puts i
end

Ruby also has its own tricks and shortcuts that would make even a serious Perl hacker happy. The following line does the very same thing as the examples above:

puts *(1..10)

This kind of flexibility and simplicity makes Ruby an approachable language for software developers and web designers of all levels.

While PHP is a web-friendly programming language, Rails is a web application framework written in Ruby (and with access to all of Ruby’s functionality to boot). And because of the way Rails works, each application you build lives in the form of a project, with specific files and folders. Unlike many PHP apps which often “just work” when uploaded to a webserver, Rails apps rely on their framework and a customized hosting infrastructure (often called a “stack”). As a result, Rails applications can be a bit more challenging to deploy. Fortunately, a number of web hosting companies specialize in deploying, hosting, and managing Rails applications.

So how would you know when to use Rails and when to use PHP? There isn’t anything that one could do in Rails that they couldn’t do in PHP (or vice versa), so in the end it boils down to a matter of choice. For me personally, I have a simple rule: if I’m adding simple functionality (such as rotating header images) to an otherwise straightforward website, I’ll often use PHP. If I’m building a web application, especially one with a database, I’ll use Rails. Again, both could do either, but I find the Rails framework is wonderful for the kind of web application development I like to do.

It should be noted that there are frameworks with goals similar to those of Ruby on Rails that are written in PHP, such as CakePHP and CodeIgniter.

Mythbusting Rails

Before we delve a bit deeper into what Rails actually is, what it does, and how you’ll probably use it, I want to dispel a few myths that non-developers often have about the framework. This list actually comes from real questions that real, live people have asked me about Rails over the last few years.

Myth #1: Rails is a content management system

I’ve mentioned that Rails makes it super easy to build web applications quickly—that it has a ton of built-in functionality and pre-built components. But what Rails actually gives you—the framework we’re talking about—is code. Rails isn’t a plug-and-play piece of software that you custom-tailor for specific applications, while just integrating some design along the way. You can think of Rails as being an elaborate menu of code that developers can select from, modify, and extend to create a completely customized application.

Myth #2: Rails lets you build applications a billion times faster

In a way, the excellent “Rails makes it easy” marketing campaign has actually hurt some independent Rails development shops. Customers expect Rails applications to be rolled out in days regardless of their feature set. In reality, Rails applications aren’t written for you automatically. Rails saves developers time by letting them focus on specific application functionality instead of things like database interconnectivity. It handles the heavy lifting required to build user interaction. Developers can use this pre-built code, and spend more time making applications that are more reliable and easier to use. Rails projects can still get quite complicated. Rails developers must still write real (and often complex) code, interactions, and tests. Rails makes development more fun and it eliminates much of the tedium involved in building web applications, but it doesn’t build them for you.

Myth #3: You don’t need to be a programmer to build Rails applications

I hear that a lot, and of course it’s false. In reality, Rails developers do much more than assemble components. Sure, they use Rails conventions and build atop a comprehensive platform, but they still write brand new, unique code.

It is true, however, that you might not need to be as experienced a developer to create a Rails application as you might need to be to build, for example, a PHP, Java, or Objective-C application. This is due both to the simplicity of the Rails framework as well as the elegance and readability of the Ruby programming language, upon which Rails sits. You still need to learn to write code.

You can read the rest of this article on A List Apart, <http://alistapart.com/articles/gettingstartedwithrubyonrails>