Using Bullet with Rails 2

The Bullet gem helps you optimize your Rails app by pointing out where you have N+1 queries in your code (check out this RailsCast if you have no idea what that means).

I recently needed to set it up for an older Rails app, still running Rails 2. Here’s how I did it.

Add the gem to your gemfile. This version of bullet works with Rails 2.

gem 'bullet', '1.7.6'

Next, you need to add the bullet initializer to your development.rb.

config.after_initialize do
  Bullet.enable = true
  Bullet.alert = true
  Bullet.bullet_logger = true
  Bullet.console = true

And that’s it! You’ll now get alerts whenever N+1 queries are encountered.