A Review of ‘The Rails 3 Way’ by Obie Fernandez

By Peter Cooper

The Rails 3 Way is the much awaited, Rails 3-focused followup to The Rails Way, a popular Rails book (and, dare I say, bible) by Obie Fernandez. It features forewords by David Heinemeier Hansson and Yehuda Katz and checks in at a desk-thumping 759 pages of full-on Rails 3 goodness (despite the book sites claiming 850 pages). I've given it the once-over.

My General Conclusion

The Rails 3 Way is an interesting book representing a large amount of effort digging into Rails 3. It shares insights and technical knowledge you'd struggle to patch together from blog posts and documentation. It's a very opinionated book and will not be to everyone's taste. For starters, ERb isn't covered at all, instance variables in views are scowled at, and Test::Unit is treated with contempt.

It's not an introductory book in any sense and Obie acknowledges this in his introduction (Rails newbies need Michael Hartl's awesome Rails Tutorial Book and Screencasts). Obie bills it as a "day-to-day reference for the full-time Rails developer" - a fair description IMHO. The book feels disjointed in places and has a scattershot approach to what it cares to cover. You need to be clued up to digest this book properly and I discuss these feelings more at the end of this post.

For an intermediate to expert Rails developer (especially one yet to move to Rails 3) or an expert Rubyist new to Rails The Rails 3 Way is a useful book that unearths some of the trickier parts of Rails 3 that a professional needs to know about. I recommend it - but not as wholeheartedly as the original edition for a number of reasons covered later in this post.

Who Should Buy It?

Existing Rails 3 experts (to use as a reference and "refresher")

Rails 1.x and 2.x gurus who haven't yet made a serious effort with Rails 3 (as you'll know what parts are useful to you or not)

Confident Rubyists with an interest in Rails 3 (ditto)

People prepared to use the book as part of a wider library of Rails 3 books as the author intended

Who Shouldn't Buy it?

Anyone who doubts their confidence with Ruby and is unable to work around the book's flaws

Total newcomers to Ruby and Rails

People expecting an exhaustive reference to Rails 3

How to Buy The Rails 3 Way

The Rails 3 Way is currently available on Amazon in paperback form ($31.49 at time of writing) and on the Kindle ($36.80), as well as in a PDF form ($35.99) on InformIT. You can also read it at no extra charge on Safari Books Online if you're a member (I recommend it - a great service and they even have an iPad app to read 1000s of tech books now).

The Book's Structure

To give you a taster, the main chapters are:

Rails Environments and Configuration Routing REST, Resources, and Rails Working with Controllers Working with Active Record Active Record Migrations Active Record Associations Validations Advanced Active Record Action View All About Helpers Ajax on Rails Session Management Authentication XML and Active Resource Action Mailer Caching and Performance RSpec Extending Rails with Plugins Background Processing

The Criticism

As much as I recommend this book for its provenance, its uniqueness, and because, well, Obie is just a damn nice guy, a review is not a review without some insightful criticism. Sadly, I have some.

Those Strong Opinions

On Twitter, Obie Fernandez noted that The Rails 3 Way is "purposely opinionated and not an introductory book." This is an understatement and a half. The Rails 3 Way is, like the framework it describes, opinionated but those opinions don't necessarily match with those of Rails itself. For example, ERb isn't covered at all. From the book:

I think Haml is such a superior choice over ERb, that this edition does not cover ERb at all.

Not only this, but Haml isn't really explained with merely a reference to the official Haml homepage given. Not necessarily a bad thing but it makes the book unsuitable for developers without the confidence to accurately judge things for themselves. Haml may or may not be suitable for your project and you need to have figured that out before hitting this book.

I'm on the fence with Haml. It's not my cup of tea but I'm not in one of the strongly-opinionated hordes that loves or hates it. Its structure seems to produce rich benefits for many (approx 47% of respondents to Hampton Catlin's 2010 Ruby Survey showed a preference for it). Not being a Haml user, though, I found the code examples relating to views more taxing to parse than I'd have liked. I suspect a Haml user would find well-formatted ERb easy to read and to re-implement as they wish.

The same issues with strong opinions pop up elsewhere. Test::Unit is ignored in deference to RSpec and a curious technique called Decent Exposure is pushed as a way to never use instance variables in your views.

Odd Structure and Patchy Coverage

This needs bulletpoints:

The introduction starts: "As I write this new introduction in the spring of 2010, the official release of Rails 3.0 is looming [..]" As soon as I read this I had to tweet: "Man, publishing is slooooow!" But this lag represents no small part of some of my other concerns..

Many sections of the book feel curiously short or scattershot in their coverage. The AJAX on Rails chapter is a mere 16 pages. The RSpec chapter is 33 pages long and provides only an overview (and says as much) though given the recent release of RSpec 2.0 and the new RSpec book, this may be a plus. Oh, and Rails Engines aren't discussed or covered at all except for a small sidenote that links you to this. It's not all bad though - some chapters are great, complete guides, such as Active Record Associations and Advanced Active Record.

The chapter is a mere 16 pages. The RSpec chapter is 33 pages long and provides only an overview (and says as much) though given the recent release of RSpec 2.0 and the new RSpec book, this may be a plus. Oh, and Rails Engines aren't discussed or covered at all except for a small sidenote that links you to this. It's not all bad though - some chapters are great, complete guides, such as Active Record Associations and Advanced Active Record. A lot can be gathered from what's not covered or mentioned in the book: Cucumber, Capybara, Selenium, Webrat, Searchlogic, SASS, factory_girl, thor, Mongrel, Passenger.. It wouldn't be expected for a book like The Rails 3 Way to go into depth with many of these tools but having no mentions of them when related issues are raised feels like a missed opportunity to give people some guidance or reminders.

Cucumber, Capybara, Selenium, Webrat, Searchlogic, SASS, factory_girl, thor, Mongrel, Passenger.. It wouldn't be expected for a book like to go into depth with many of these tools but having no mentions of them when related issues are raised feels like a missed opportunity to give people some guidance or reminders. The lack of Webrat is bizarre since the only full integration test in the book clearly uses it. Webrat is neither mentioned nor explained. I have some sympathies for Obie on this, though, as I've found getting Webrat to run on Rails 3 with the latest RSpec to be nigh on impossible so far. Capybara (Webrat's heir assumptive) would be even better but that's not mentioned at all.

Webrat is neither mentioned nor explained. I have some sympathies for Obie on this, though, as I've found getting Webrat to run on Rails 3 with the latest RSpec to be nigh on impossible so far. In the introduction, Obie states: "In cases where third-party code is better than the built-in Rails functionality, we don’t cover the built-in Rails functionality (pagination is a good example)." This seems a reasonable course of action, but it would have been nice for this "better" code to be mentioned in a more formal way than as a single erroneously placed footnote on page 399 that was meant to link to attachment_fu..

The concept of using a different ORM than ActiveRecord is mentioned only once , in the context of running --skip-migration on a rails generate in order to prevent ActiveRecord migrations being generated. Considering what a big deal ORM agnosticism was when developing Rails 3, this is a disappointment.

, in the context of running on a in order to prevent ActiveRecord migrations being generated. Considering what a big deal ORM agnosticism was when developing Rails 3, this is a disappointment. Concepts are sometimes used in code but not mentioned in the text. In the RSpec chapter, for instance, the first example includes a call to factory_girl's Factory method, yet nothing about factory_girl or the benefits of factories is covered. I only know it's factory_girl being called because the gem's name appears in the copy-and-pasted output from running bundle install 500 pages earlier. And why put a scope condition based on a 7.days.ago call into a lambda when there are no params? I know why, but a note would be appreciated.

In the RSpec chapter, for instance, the first example includes a call to factory_girl's method, yet nothing about factory_girl or the benefits of factories is covered. I only know it's factory_girl being called because the gem's name appears in the copy-and-pasted output from running 500 pages earlier. And why put a scope condition based on a call into a when there are no params? I know why, but a note would be appreciated. Tests are rarely used or demonstrated except in the RSpec overview, Working With Active Record (4 test snippets in 39 pages), Action Mailer (once), and Active Record Associations (6 test snippets in 50 pages). Oddly, though, 4 stray instances of using Test::Unit instead pop up when writing a test for a belongs_to association - it's never used again anywhere else in the main part of the book..

So I'm Unsure

I hesitated to post these criticisms because Obie's a great guy and the first edition of The Rails Way was epic and definitive. I'd hope someone can come along and say "You read the book wrong! Here's why x, y, and z are like they are!" but from my first run through, I'm torn. I'm a little saddened by what I perceive as flaws yet impressed by the sheer depth and pockets of brilliance.

Nonetheless, I recommend the book. It's a flawed champ. While there are other great Rails books in the pipeline, The Rails 3 Way offers a lot right now, as long as you're either happy to look past its flaws or skilled enough to mentally fill in the blanks..

The Rails 3 Way is currently available on Amazon in both paperback (at $31.49) and Kindle ($36.80) formats, or in a PDF version ($35.99) on InformIT.