Skip to content

Instantly share code, notes, and snippets.

@doitian
Created April 8, 2012 21:52
Show Gist options
  • Save doitian/2340035 to your computer and use it in GitHub Desktop.
Save doitian/2340035 to your computer and use it in GitHub Desktop.
Use pry to start rails console without adding to Gemfile

Tested under Rails 3.1.1

First install gems for pry session, e.g.

gem install pry pry-doc awesome_print bundler

bundler is required so that we can load Gemfile in Rails project.

Then just download rpry file into a directory which is in PATH and make it executable. Go to your Rails project root and run

rpry

Or start in production environment:

rpry production
#!/usr/bin/env ruby
require 'rubygems'
require 'pry'
require 'pry-doc'
require 'awesome_print'
if ARGV.first && !ARGV.first.index("-") && env = ARGV.shift
ENV['RAILS_ENV'] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
end
ARGV.unshift "console"
APP_PATH = File.expand_path('config/application')
require APP_PATH
module Rails
class Console
IRB = ::Pry
end
end
require 'rails/commands'
@doitian
Copy link
Author

doitian commented Apr 8, 2012

Gem rails-console-pry is created from this gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment