1.3. What Rails IsSo far, we've been thinking about Ajax; let's shift now to Rails. Ruby on Rails (or more commonly, just Rails) is a full-stack MVC web development framework for the Ruby language. That's a mouthful. Let's break down the concepts one by one: Full-stack means that the framework encompasses almost everything you'll need to create a finished product. It's perhaps a bit of a misnomer, because most applications will also require a persistence layer (a database) and a web server. But at the application level, Rails has everything needed by most projects, most of the timethere's no need to select an additional templating system or database-mapping system. MVC stands for Model View Controller, which is simply a way of organizing your application into chunks, according to their responsibility.
Web applications don't have to be organized according to MVCmany developers freely mix all three parts. But as systems get larger, the mixed-up method quickly becomes untenable and prone to error. Code can be organized lots of ways, but MVC is the Rails way and a time-tested approach to keep your application maintainable. A framework can be seen as a set of constraints for your program. At first, that sounds like a bad thingwhy constrain yourself? But it turns out that by embracing constraints for a specific purpose, you actually enable creativity, by focusing energy on the problem at hand. The Rails framework is a set of constraints that enables effective web development. When I was in college, I studied in Paris for a while, and I often visited cyber cafés to write friends back in the U.S. The experience introduced me to non-English keyboard layouts. Usually they were French, but I also ran into German and Spanish. The layouts of all the keyboards are similar, but just different enough to be a hasslea few letters swapped here and there, slowing down my typing tremendously. One day, while emailing a friend, I was unable to find a way to type the letter m for the life of me. That's when I discovered the joys of lipograms: compositions in which one or more letter is intentionally omitted, just for the challenge. So that day I wrote a reluctant lipogram, and I've been fascinated with them since. Take the novel Gadsby by Ernest V. Wright, written entirely without the letter e. Here's the first sentence: If Youth, throughout all history, had had a champion to stand up for it; to show a doubting world that a child can think; and, possibly, do it practically; you wouldn't constantly run across folks today who claim that 'a child don't know anything.' Lipograms are about imposing artificial constraints. The interesting thing about writing them is the side effect: they force you to think more creatively about the problem of communication. When you deny yourself complete freedom in writing, it often actually allows you to express yourself better. Lipograms are an extreme example, but poetry and lyrics work the same way. Often the reason they have so much expressive power is because the writer is limited metrically or in rhyme. Working in the Rails framework exhibits the same paradox. By embracing constraints and voluntarily giving up freedom along some axis, you enable a great deal of creative and productive power. Ruby is an elegant, object-oriented, dynamically typed programming language, with roots in List, Perl, and Smalltalk. Its creator, Yukihiro "Matz" Matsumoto, has said Ruby is "optimized for programmer joy." Ruby has been around since 1995 and, pardon the cliché, is quite big in Japan. But until Rails' catalytic effect, it didn't receive much attention in the West. Because Rails' power is so closely tied to Ruby's expressiveness, it can be hard to separate the two. It was no accident that David Heinemeier Hansson (or DHH, as he's affectionately known), the creator of Rails, acknowledged his debt to Ruby right in the framework name, Ruby on Rails. 1.3.1. Rails MantrasThe Rails community has a number of mantras, guiding principles for its development. Understanding them goes a long way toward understanding Rails.
|