small medium large xlarge

Rails Recipes: Rails 3 Edition


Cover image for Rails Recipes

Rails Recipes

Rails 3 Edition


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.

Customer Reviews

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.

- Sagecreek Productions

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

See All Reviews

Contents & 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


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.