Skip to content

Instantly share code, notes, and snippets.

@ro31337
Last active March 11, 2021 21:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ro31337/11b0ce2efaf36a77be87ff2da92e04d7 to your computer and use it in GitHub Desktop.
Save ro31337/11b0ce2efaf36a77be87ff2da92e04d7 to your computer and use it in GitHub Desktop.
Pry for Rails setup

How to make awesome pry for Rails

Tested on Rails 5.1, for development, test and production (!).

At the top of your Gemfile (don't add to :development or :test):

  • Add gem 'pry' to your Gemfile
  • Add gem 'awesome_print' to your Gemfile

Make sure you updated your application.rb (not development.rb):

module App
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.1

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.
    config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

    # ADD THESE 4 LINES:
    console do
      require 'pry'
      config.console = Pry
    end
  end
end

Make sure to have the following in your ~/.pryrc:

require 'awesome_print'
AwesomePrint.pry!

Then just spring stop && rails c.

Without pry for rails:

image

With pry for rails:

image

I would also recommend adding these to your :development, :test section:

  gem 'pry-byebug' # for `next`, `step`, etc. commands
  gem 'pry-stack_explorer' # for `show-stack` command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment