(Beta Version) Introduction vi
Sample Code and Listings
The domains chosen for the code samples should be familiar to almost all professional developers. They
include time and expense tracking, auctions, regional data management, and blogging applications. I don’t
spend pages explaining the subtler nuances of the business logic for the samples or justify design decisions
that don’t have a direct relationship to the topic at hand. Following in the footsteps of my series colleague Hal
Fulton and The Ruby Way, most of the snippets are not full code listings—only the relevant code is shown.
Ellipses (…) denote parts of the code that have been eliminated for clarity.
Whenever a code listing is large and significant, and I suspect that you might want to use it verbatim in your
own code, I supply a listing heading. There are not too many of those. The whole set of code listings will not
add up to a complete working system, nor are there 30 pages of sample application code in an appendix. The
code listings should serve as inspiration for your production-ready work, but keep in mind that it often lacks
touches necessary in real-world work. For example, examples of controller code are often missing pagination
and access control logic, because it would detract from the point being expressed.
Some of the source code for my examples can be found at http://github.com/obie/tr3w_time_and_expenses.
Note that it is not a working nor complete application. It just made sense at times to keep the code in the
context of an application and hopefully you might draw some inspiration from browsing it.
Concerning 3rd-Party RubyGems and Plugins
Whenever you find yourself writing code that feels like plumbing, by which I mean completely unrelated to
the business domain of your application, you’re probably doing too much work. I hope that you have this
book at your side when you encounter that feeling. There is almost always some new part of the Rails API or
a third-party RubyGem for doing exactly what you are trying to do.
As a matter of fact, part of what sets this book apart is that I never hesitate in calling out the availability of
third-party code, and I even document the RubyGems and plugins that I feel are most crucial for effective
Rails work. In cases where 3rd-party code is better than the built-in Rails functionality, we don’t cover the
built-in Rails functionality (pagination is a good example).
An average developer might see his productivity double with Rails, but I’ve seen serious Rails developers
achieve gains that are much, much higher. That’s because we follow the Don’t Repeat Yourself (DRY) principle
religiously, of which Don’t Reinvent The Wheel (DRTW) is a close corollary. Reimplementing something
when an existing implementation is good enough is an unnecessary waste of time that nevertheless can be
very tempting, since it’s such a joy to program in Ruby.
Ruby on Rails is actually a vast ecosystem of core code, official plugins, and third-party plugins. That
ecosystem has been exploding rapidly and provides all the raw technology you need to build even the most
complicated enterprise-class web applications. My goal is to equip you with enough knowledge that you’ll be
able to avoid continuously reinventing the wheel.
Recommended Reading and Resources
Readers may find it useful to read this book while referring to some of the excellent reference titles listed in
this section.