A delicious blend of Ruby and Rails…

Book Review: Advanced Rails Recipes

January 6th, 2008 benhughes

I’ve owned the original “Rails Recipes” book by Chad Fowler for a while now and it’s packed full of interesting information, but little of it I would consider “advanced”. When I heard a new book by The Pragmatic Programmers called “Advanced Rails Recipes”, meant to be similar in form to the previous book but explaining more advanced techniques, I was very interested. Unfortunately it seems the publish date of this book has been pushed back a few times and it is now mid-March. Luckily it is available in beta PDF form online so last night I took the plunge and decided to buy it. It’s quick to read through and several of the recipes I skipped over because I wasn’t particularly interested, but suffice it to say that there is a lot of good stuff in this book. Some of the content isn’t very original, but some recipes really exceeded my expectations in originality and usefulness.

I won’t give an outline of the book since that’s available online, but let me point out a few very interesting recipes:

  • Using IRB_RC to define useful shortcuts for yourself when navigating around your application with script/console.
  • Efficiently storing model-backed data in constants using class-level ActiveRecord find’s. Example: load all of your states into an Array when the application starts rather than loading them each time a form is displayed that needs to use them.
  • Capistrano multi-environment deployments which allow you to do things like “cap staging deploy” and “cap production deploy”. I’ve been doing this for a while with capistrano-ext but really capistrano-ext isn’t even needed. Every developer using capistrano should be making use of this and a staging environment.
  • Keeping database.yml and other files out of Subversion using a Capistrano after filter when deploying apps.
  • Keeping certain data outside the multiple-release capistrano paradigm by symbolic linking folders within public to subdirectories in shared. This is perfect for establishing a place to upload via FTP without requiring someone to go through the SVN commit and capistrano deploy route. I’ve also used this before but the mechanism described in the book is more elegant.
  • SQL query tracing – finding out where queries are being run and what is going on behind the scenes. Could come in useful when debugging a nasty situation.
  • Using a master/slave database configuration for large applications with Rick Olsen’s masochism plugin.
  • My favorite: Handling complex forms spanning multiple models each with possible one-to-many or many-to-many relationships using the “presenter” pattern. Essentially this allows you to have a layer of design abstraction between the controller and the models whereby you can design a “presenter” which acts as as “manager” of multiple model objects meant to be displayed using the same form. Difficult to explain in full here (buy the book!) but this sounds like a very elegant solution for more data-complex applications. I may do some refactoring with Rarenewspapers.com’s back-end to use this pattern.

The book is still in beta form and there are definitely errors. Hopefully some more recipes will also be added (I’m hungry for more!) before the book is released, but ultimately the knowledge presented in Advanced Rails recipes will be very insightful for professional Rails developers.

Book Review: The Rails Way

December 8th, 2007 benhughes

Whenever I go to a bookstore I am sure to check out the Rails/Ruby section (constantly increasing in size!) for any new titles I may not be aware of. I was pleasantly surprised to find a new large Rails book that almost went unnoticed: The Rails Way by Obie Fernandez. I say almost went unnoticed because the book cover looks almost identical to The Ruby Way, so it’s easy to gloss over if you don’t look carefully.

It is easy to see by the sheer size that this book, weighing in at 850 pages, that it is very in-depth. The author explicitly states in the introduction that this is not a book for Ruby on Rails beginners. It was intended on being primarily an information-packed reference book for professional developers working with Ruby on Rails. The most appealing characteristic of the book is that it covers Rails 2.0, the first book to my knowledge that does.

After reading the book (it’s a long read!) I can definately say that this is a very valuable book for Rails developers. Typically after reading the Agile book, Rails developers end up craving knowledge of more advanced Rails techniques and plugins, and this book certainly delivers in this respect. Sprinkled throughout the detailed description of the Rails API are useful plugins, tips, and techniques that the author has come across in his development experience. Also included are many snippets of code from the Rails source code that help explain how key things work in Rails.

A full chapter outline is available online so I won’t bother duplicating that work, but let me point out a few areas of Rails that this book covers:

  • Rails Environment and Configuration – explains the Rails boot process and the automatic class loader, as well as other things behind the scenes that make Rails tick – very interesting.
  • New Rails 2.0 RESTful Routes – Covers some changes and enhancements to the RESTful routing features of Rails 2.0.
  • Advanced ActiveRecord – Really gives detailed information about ActiveRecord, even briefly explaining the AssociationProxy class that masquerades as an Array for those has_many associations.
  • Prototype Reference
  • Selenium Testing
  • RSpec
  • Using subversion with Rails and piston
  • Rails deployment with Capistrano
  • Common production configuration setups
  • Background processing with BackgrounDRb
  • ActiveSupport Reference

The last few topics in particularly were mostly until now the realm of random blog posts online with no solid resource in print.

In short, The Rails Way is a must-have for any developer working professionally with Ruby on Rails. Far from being a programming resource only, it helps you become an all-around better developer by arming you with techniques, new plugins, and tools to improve your productivity. Targeted towards the advanced user, this book is packed full of information that will greatly improve your facility with Rails. Buy it today!