This page will show you how to configure your Rails application to use Pry instead of IRB.
Add the following as a initializer - it provides you with access to the entire Rails stack, and all the useful Rails3 console helpers. After the initializer is in place, you can go ahead and load the console normally using
MyApplication::Application.configure do # Use Pry instead of IRB silence_warnings do begin require 'pry' IRB = Pry rescue LoadError end end end
To have access to the entire Rails stack, with access to helpful Rails console commands such as
reload!, you can use this snippet (placing in your
# Load plugins (only those I whitelist) Pry.config.should_load_plugins = false Pry.plugins["doc"].activate! # Launch Pry with access to the entire Rails stack. # If you have Pry in your Gemfile, you can pass: ./script/console --irb=pry instead. # If you don't, you can load it through the lines below :) rails = File.join Dir.getwd, 'config', 'environment.rb' if File.exist?(rails) && ENV['SKIP_RAILS'].nil? require rails if Rails.version[0..0] == "2" require 'console_app' require 'console_with_helpers' elsif Rails.version[0..0] == "3" require 'rails/console/app' require 'rails/console/helpers' else warn "[WARN] cannot load Rails console commands (Not on Rails2 or Rails3?)" end end
It will boot the Rails environment by loading
RAILS_ROOT/config/environment.rb, and then load any helper commands Rails provides you with. This is a solution you can use for Rails2, or Rails3.
After you've setup the
.pryrc file, you can invoke Pry normally in the root of your Rails project, with the added bonus that the Rails stack is loaded for you, plus all the useful helper console commands:
This is a gem which causes
rails console to open
Add this line to your gemfile:
gem 'pry-rails', :group => :development
bundle install and enjoy!
See the pry-rails project page for more information.
This approach simply piggy-backs on IRB.
If you're using a Gemfile, you should add
gem 'pry', :group => :development to it.
This technique is discussed in more depth here.
begin require "pry" Pry.start exit rescue LoadError => e warn "=> Unable to load pry" end
To convince Heroku to use Pry as the console instead of IRB create a file called pry in your app root and then add the following to the file:
#!/usr/bin/env ruby # To launch push this into your Git then do: # heroku run console pry # heroku console pry require 'pry' pry
After you have the above, commit it and push it, and then you can do
heroku run console pry