Pry Tips Fall 2021

Can you start pry early in the Rails booting process, such as in an initializer file?

If you just put in a binding.pry inside one of your initializer files, you’ll probably see a warning like this. Assume the top-level directory of your project is my_project.

Error: Cannot open "/Users/my_name/projects/my_project/<main>" for reading.

Needs require to load pry correctly

The fix for this is to put these two lines at the top of the file where you’re trying to use binding.pry:

require 'pry'
require 'pry-byebug

Sidekiq Example

For example, here’s the sample config:

To add a binding.pry to that file to do some exploration, just add those two requires to the top of the initializer file.

And when you clean up your binding.pry, don’t forget to remove the extra requires!