1. Introducing the Rails Framework
Rails is a web application framework for the Ruby programming language. Rails is well thought out and practical: it will help you build powerful web sites quickly, with code thats clean and easy to maintain.
The goal of this book is to give you a thorough and complete understanding of how to build dynamic web applications with Rails. This means more than just showing you how to use the specific features and facilities of the framework, and more than just giving you a working knowledge of the Ruby language. Rails is quite a bit more than just another tool: it represents a way of thinking. To completely understand Rails, its essential that you know about its underpinnings, its culture and aesthetics, and its philosophy of web development.
If you havent heard it already, youre sure to notice the phrase the Rails way cropping up every now and again. It echoes a familiar phrase that has been floating around the Ruby community for a number of years: the Ruby way. The Rails way is usually the easiest waythe path of least resistance, if you will. This isnt to say that you cant do things your way, nor is it meant to suggest that the framework is constraining. It simply means that if you choose to go off the beaten path, you shouldnt expect Rails to make it easy for you. If youve been around the UNIX circle for any length of time, you may think this idea bears some resemblance to the UNIX mantra: Do the simplest thing that could possibly work. Youre right. This chapters aim is to introduce you to the Rails way.
The Rise and Rise of the Web Application
Web applications are extremely important in todays world. Almost everything we do today involves web applications. We check our e-mail on the Web, and we do our banking on the Web. We even use our phones to access the web more than we actually make phone calls! As connections get faster, and as broadband adoption grows, web-based software, and similarly networked client or server applications, are poised to displace software distributed by more traditional (read, outdated) means.
For consumers, web-based software affords greater convenience, allowing us to do more from more places. Web-based software works on every platform that supports a web browser (which is to say, all of them), and theres nothing to install or download. And if Googles stock value is any indication, web applications are really taking off. All over the world, people are waking up to the new Web and the beauty of being web based. From e-mail and calendars, photos and videos, to bookmarking, banking, and bidding, were living increasingly inside the browser.
Due to the ease of distribution, the pace of change in the web-based software market is fast. Unlike traditional software, which must be installed on each individual computer, changes in web applications can be delivered quickly, and features can be added incrementally. Theres no need to spend months or years perfecting the final version or getting in all the features before the launch date. Instead of spending months on research and development, you can go into production early and refine in the wild, even without all the features in place.
Can you imagine having a million CDs pressed and shipped, only to find a bug in your software as the FedEx truck is disappearing into the sunset? That would be an expensive mistake! Software distributed this way takes notoriously long to get out the door because before a company ships a product, it needs to be sure the software is bug free. Of course, theres no such thing as bug-free software, and web applications arent immune to these unintended features. But with a web application, bug fixes are easy to deploy.
When a fix is pushed to the server hosting the web application, all users get the benefit of the update at the same time, usually without any interruption in service. Thats a level of quality assurance you cant offer with store-bought software. There are no service packs to tirelessly distribute and no critical updates to install. A fix is often only a browser refresh away. And as a side benefit, instead of spending large amounts of money and resources on packaging and distribution, software developers are free to spend more time on quality and innovation.
Web-based software has the following advantages; it is:
Easier to distribute
Easier to deploy
Easier to maintain
Platform-independent
Accessible from anywhere
The Web Isnt Perfect
As great a platform as the Web is, its also fraught with constraints. One of the biggest problems is the browser itself. When it comes to browsers, there are several contenders, each of which has a slightly different take on how to display the contents of a web page. Although there has been movement toward unification and the state of standards compliance among browsers is steadily improving, there is still much to be desired. Even today, its nearly impossible to achieve 100% cross-browser compatibility. Something that works in Internet Explorer doesnt necessarily work in Firefox, and vice versa. This lack of uniformity makes it difficult for developers to create truly cross-platform applications, as well as harder for users to work in their browser of choice.
Browser issues aside, perhaps the biggest constraint facing web development is its inherent complexity. A typical web application has dozens of moving parts: protocols and ports, the HTML and cascading style sheets (CSS), the database and the server, the designer and the developer, and a multitude of other players, all conspiring toward complexity.
Despite these problems, the new focus on the Web as a platform means the field of web development is evolving rapidly and quickly overcoming obstacles. As it continues to mature, the tools and processes that have long been commonplace in traditional, client-side software development are beginning to make their way into the world of web development.
The Good Web Framework
Among the tools making their way into the world of web development is the framework. A framework is a collection of libraries and tools intended to facilitate development. Designed with productivity in mind, a good framework provides a basic but complete infrastructure on top of which to build an application.
Having a good framework is a lot like having a chunk of your application already written for you. Instead of having to start from scratch, you begin with the foundation in place. If a community of developers uses the same framework, you have a community of support when you need it. You also have greater assurance that the foundation youre building on is less prone to pesky bugs and vulnerabilities, which can slow the development process.
A good web framework can be described as follows:
Full stack: Everything you need for building complete applications should be included in the box. Having to install various libraries or configure multiple components is a drag. The different layers should fit together seamlessly.
Open source: A framework should be open source, preferably licensed under a liberal, free-as-in-free license like the Berkeley Software Distribution (BSD) or that of the Massachusetts Institute of Technology (MIT).