Now Available: Objects on Rails

It’s Done!

I am very happy to announce that today, my latest eBook Objects on Rails is complete!

As promised, the full text of the book is available to read online, for free.

In addition, the book is available for download in DRM-free PDF, Epub, and Mobi (Kindle) formats, along with full source code, for $5 USD.

I’m also dabbling in a limited form of “pay what you like”: If you’re feeling extra generous and want to contribute more than $5 in order to keep me working on projects like this, there’s a “Sponsor Edition” you might be interested in. See the store page for more details.

About the book

What is Objects on Rails? I’m not going to get into too much detail here, since you can just go read it if you want. But in a nutshell…

Objects on Rails is a sort of “developer notebook” of some ideas and techniques for applying classic object-oriented principles to Rails development. In order to write it I revisited the classic “blog” example, and tried to apply what I’ve learned over the years about OO and TDD to each step. And then at each step I carefully documented what I did, and wrote down the thinking behind my decisions. Sometimes I went on extended digressions about certain patterns and antipatterns. Other times I went down dead-end sidings, thought better of it, and tried to explain the thinking that lead me down them in the first place.

An early reader jokingly called it “how to build a blog in 15 months”, which I got a chuckle out of, because it’s kind of true. I picked a blog example because it’s something that’s familiar to everyone, a kind of “neutral canvas” that wouldn’t distract from the ideas being demonstrated. But the design choices I chose to illustrate are of the kind that are primarily relevant for growing and evolving large systems. Of course, every large, complex system starts out as a small simple one; and a robust architecture comes from making good decisions early on in the process.

While the process of development shown in the text is a more disciplined, thoughtful, and design-oriented one than you’d find in most “get kick-started fast” guides, I’ve tried hard to keep it pragmatic. A recurring theme in the book is trying to find a “middle way” between the Rails “golden path” and OO orthodoxy. I start with the premise that Rails is a fantastic foundation to build on for growing modern objected-oriented web applications. Then I make incremental additions that I try to keep more or less “with the grain” of Rails. Just as one example, you won’t find a lot of coverage in the book about strictly separating ActiveRecord classes from business logic. What you will find are some tips and tricks for treating the ActiveRecord part of your models as an implementation detail, so that if you ever do decide to draw a wider distinction between the two, it shouldn’t be a massive ordeal to tease them apart.

For those who enjoy bullet lists, here are some of the topics covered:

  • Working from the outside in, starting from how the app should look to the user.
  • Starting with plain objects and leaving persistence for later.
  • Treating ActiveRecord as a private implementation detail.
  • Sticking to the language of the domain.
  • Using placeholder objects for rapid iteration.
  • Incrementally extending objects with ActiveModel.
  • Trees of objects versus “lone wolf” objects.
  • Simple dependency injection with sensible defaults.
  • Factoring out object roles.
  • Keeping tests isolated and fast.
  • When to throw tests away.
  • Enabling objects to render themselves with Exhibits.
  • Using Exhibits to deliver a rich hypermedia API.

Enjoy, won’t you?

Well I think that’s enough introduction. I hope you enjoy the book, and if nothing else that it gives you some food for thought. If you have questions, comments, or just want to discuss OO and Rails in general, please do join the discussion group.

This entry was posted in Announcements, Books. Bookmark the permalink.
  • http://floatboth.com MyFreeWeb

    s/ActiveRecord/ActiveModel/ maybe? Because that’s Mongoid for me.

  • http://website-in-a-weekend.net/ Dave Doolin

    I’m going through ActiveRecord business logic gyrations right now.  Not pretty. I don’t anticipate getting it right the first time, but I’m cool with that.

    As I recall from listening to a Rogues podcast you have another volume planned…? Or were you “volunteered”? When can I pre-order?

  • blake41

    Not sure if this is the right place to post this, but for lack of a better idea.
    Page 47 of the PDF, line 15

    @it.pubdate.class.must_equal(DateTime)It appears that the DateTime class is not included by default (ruby 1.9.2p290).  I get an error when I add this to my code.  I fixed it by requiring the date class.

    • http://avdi.org Avdi Grimm

      Thanks! As I mentioned in the introduction, I’ve elided parts of the example code, including some “require” statements.

      Feel free to contribute more feedback in the mailing list: https://groups.google.com/d/forum/objects-on-rails

      • blake41

        Ahh, you’re totally right.  Good to know I’m supposed to be doing my own thinking as I work through this.  Let me also say this book is EXCELLENT.  Loving this new way of thinking.  As a self taught hacker it’s so valuable to learn how I SHOULD be doing things as opposed to just hacking my way through and causing myself problems later.  Love the blog and the book.  Thanks so much.

        • http://avdi.org Avdi Grimm

          I’m so glad you’re enjoying them!

  • http://twitter.com/quartzmo Chris Smith

    Avdi,

    Can you explain how you decided on this particular flavor of ebook freemium? Is there a large (enough) percentage of online readers who are willing to pay for the tablet/Kindle experience? Or is it more based on appreciation?
    Also, when I heard the book and its $5 price mentioned at MountainWest RubyConf, I thought Wow! Cheap! Wasn’t your previous book $15? Why the reduction?

  • Pingback: Tea-Driven Development :: Hexagonal Rails – Introduction