Greg Malcolm
Greg Malcolm

Reputation: 3427

How to I start a rails console with pry turned off?

Sometimes I have reason to want to start the rails console as an irb repl rather than pry (as awesome as pry is). It will default to pry because pry has in the Gemfile. Hows is that done nowadays?

I think there used to be a --irb option when running rails console but that seems to be gone now. I get a deprecation error message when I try it.

More details

If I just run "rails console" it takes me to pry.

If I run "rails console -irb=irb":

$ rails c -irb=irb                                                                                                                                                                         
--irb option is no longer supported. Invoke `/your/choice/of/ruby script/rails console` instead

Relevent lines from my Gemfile:

gem 'rails', '3.2.18'
gem 'pry-rails'
gem 'pry-plus'

Upvotes: 17

Views: 9800

Answers (5)

knagode
knagode

Reputation: 6125

You can also do it once console has already been started via IRB.start method.

Upvotes: 0

Matthew Hinea
Matthew Hinea

Reputation: 1931

Inspired by the answers above, I added the following to the class definition in application.rb so that Pry is toggleable from the console:

console do
  if ENV['IRB']
    require 'irb'
    config.console = IRB
  end
end

You can then run rails c to get a Pry console, and IRB=true rails c to get an IRB console. This is easily modified if you want the inverse. Works in Rails 4 and 5.

Upvotes: 2

ReggieB
ReggieB

Reputation: 8257

Launching pry when calling rails console or rails c is set up by the pry-rails gem. If you look in the pry-rails issues there is one that describes a solution.

Define the environment variable DISABLE_PRY_RAILS as 1.

So you can call rails console without pry with:

DISABLE_PRY_RAILS=1 rails c

Upvotes: 41

Alex Levine
Alex Levine

Reputation: 1597

Works in Rails 4: In your application.rb, inside your Application class, drop this puppy in.

# Use the IRB console instead of the Pry one
console do
  require 'irb'
  config.console = IRB
end

I couldn't take the Pry console anymore. It kept putting my cursor in odd places at unpredictable times. I can't even describe it but if you know what I'm talking about and know the solution, please let me know.

Upvotes: 6

Greg Malcolm
Greg Malcolm

Reputation: 3427

For the benefit of anyone who runs into the same problem, this is my (crappy) workaround.

I wrapped the pry gems in Gemfile with this:

...
unless ENV['NOPRY']
  gem 'pry-rails'
  gem 'pry-plus'
end
...

Then run this from the unix terminal:

NOPRY=true bundle install
NOPRY=true rails console

Not pretty, but gets the job done...

Upvotes: 1

Related Questions