Thousands of developers have used the first edition of Rails Recipes to solve the hard problems. Now, five years later, it’s time for the Rails 3 edition of this trusted collection of solutions, completely revised by Rails master Chad Fowler.

Out of Print

This book is currently out of print.

About this Book

  • 296 pages
  • Published:
  • Release: P1.0 (2012-04-03)
  • ISBN: 978-1-93435-677-7

Written for novice to intermediate Rails developers, Rails Recipes: Rails 3 Edition is packed with solutions to 70 of the most vexing problems you’re likely to face on the job. From building custom forms and powering pages with jQuery to integrating with legacy databases, it’s all here. Each recipe has been updated to reflect the latest features of Rails 3 and each lays out a distinctive solution to a problem you may be facing today or could well encounter tomorrow. In addition, you’ll find half the book is stocked with new eye-opening solutions to such common problems as how to extend Rails, test and deploy your sites, or add a web service to your actions. And each recipe not only lays out a succinct solution, but explains its rationale and the technologies that make it work.

Loaded with the insights of a Rails community leader, members of the Rails core team and other experts, this is the book you’ll want to have at your side as you craft your next project.

What You Need:

Ruby 1.8.7 or above
Rails 3.1 or above

Contents and Extracts


  • Database Recipes
    • Create Meaningful Many-to-Many Relationships
    • Create Declarative Named Queries
    • Connect to Multiple Databases
    • Set Default Criteria For Model Operations
    • Add Behavior to Active Record Associations
    • Create Polymorphic Associations
    • Version Your Models
    • Perform Calculations on Your Model Data
    • Use Active Record Outside of Rails
    • Connect to Legacy Databases
    • Make Dumb Data Smart with composed_of()
    • DRY Up Your YAML Database Configuration File
    • Use Models Safely in Migrations
    • Create Self-referential Many-to-Many Relationships
    • Protect Your Data From Accidental Mass-Update
    • Create a Custom Model Validator excerpt
    • Nest has_many :through Relationships
    • Keep Your Application In Synch With Your Database Schema
    • Seed Your Database with Starting Data
    • Use Helpers in Models
    • Avoid Dangling Database Dependencies
  • Controller Recipes
    • Create Nested Resources
    • Create a Custom Action in a REST Controller
    • Create a Helper Method to Use In Both Controllers And Views
    • Trim Your REST Resources
    • Constrain Routes by Subdomain (and Other Conditions)
    • Add Web Services to Your Actions
    • Write Macros
    • Manage a Static HTML Site with Rails
    • Syndicate Your Site with RSS
    • Set Your Application’s Home Page
  • User Interface Recipes
    • Create a Custom Form Builder
    • Pluralize Words on the Fly (or Not)
    • Insert Action-Specific Content in a Layout
    • Add Unobtrusive Ajax with jQuery
    • Create One Form for Many Models excerpt
    • Cache Local Data with HTML 5 Data Attributes excerpt
  • Testing Recipes
    • Automate Tests for Your Models
    • Test Your Controllers
    • Test Your Helpers
    • Test Your Outgoing Mailers
    • Testing Across Multiple Controllers
    • Focus Your Tests With Mocking and Stubbing
    • Extract Test Fixtures from Live Data
    • Create Dynamic Test Fixtures
    • Measure and Improve Your Test Coverage
    • Create Test Data With Factories
  • Email Recipes
    • Send Gracefully Degrading Rich-Content Emails
    • Send Email with Attachments
    • Test Incoming Email
  • Big-Picture Recipes
    • Roll Your Own Authentication
    • Protect Your Application With Basic HTTP Authentication
    • Authorize Users with Roles
    • Force Your Users to Access Site Functions with SSL
    • Create Secret URLs
    • Use Rails without a Database
    • Create Your Own Ruby Gem
    • Use Bundler Groups to Manage per-Environment Dependencies
    • Package Rake Tasks for Reuse with a Gem
    • Explore Your Rails Application with the Console
    • Automate Work with Your Own Rake Tasks
    • Generate Documentation for Your Application
    • Render Application Data as Comma-Separated Values
    • Debug and Explore Your Application with the ruby-debug Gem
    • Render Complex Documents as PDFs
  • Extending Rails
    • Support Additional Content Types with a Custom Renderer
    • Accept Additional Content Types with a Custom Parameter Parser
    • Templatize Your Generated Rails Applications
    • Automate Recurring Code Patterns with Custom Generators
    • Create a Mountable Application as a Rails Engine Plug-In

About the Author

Chad Fowler is an internationally known software developer, trainer, manager, speaker, and musician. Over the past decade he has worked with some of the world’s largest companies and most admired software developers.

Chad is VP of Engineering at LivingSocial. He is co-organizer of RubyConf and RailsConf and author or co-author of a number of popular software books, including The Passionate Programmer: Creating a Remarkable Career in Software Development.

Comments and Reviews

  • Sagecreek Productions said:

    Anyone working with Rails or still adding it to their programming capabilities should consider getting Rails Recipes: Rails 3 Edition and keeping it within easy reach.

  • Even the best chefs are loathe to re-create a recipe from scratch if they know a good one already exists. Rails programmers would do well to code like a great chef cooks and have this tome on their shelf.

    —David Heinemeier Hansson Creator of Ruby on Rails; partner at 37signals; coauthor of "Agile Web Development with Rails"
  • “Rails Recipes” is a great resource for any Rails programmer. The book is full of hidden gems (no pun intended) that many programmers may not discover in their daily quest to get the job done.

    —Gary Sherman Principal of GeoApt, LLC; chair of QGIS PSC; and author of "The Geospatial Desktop"
  • “Rails Recipes” has always been the definitive guide for aspiring Rails developers. It doesn’t just cover how you could build something, but delves into the details and explains all the reasons why you should build it that way. You can be sure that if you follow the tips and tricks in this book, you’re on the right path.

    —Michael Koziarski Software developer, Rails Core team member, and partner, Southgate Labs