Skip to content

Instantly share code, notes, and snippets.

@zismailov
Last active November 1, 2017 07:36
Show Gist options
  • Save zismailov/b92b47ab899ae8beb96c985cace18795 to your computer and use it in GitHub Desktop.
Save zismailov/b92b47ab899ae8beb96c985cace18795 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