Everyday Active Record Episode 4: Using Callbacks

Posted in Development, Frameworks, Databases on July 17, 2008

Everyday Active Record Episode 4: Using Callbacks

Callbacks are a way for your application to hook into the lifecycle of Active Record models. In this episode, we’ll use callbacks to solve two database performance problems. We’ll cache a movie’s review count and its average number of stars. You’ll learn how to:

  • use Active Record callback methods
  • make callbacks conditional
  • apply before_save and before_destroy callbacks to keep cache data consistent
  • use the counter_cache option on associations
  • track dirty columns
  • destroy dependent records
  • apply other callback tips

Watch Video

Tags: Ruby, Ruby On Rails, Frameworks, Databases, ActiveRecord, ORM, The Pragmatic Programmers, Everyday Active Record