I’m trying to have a console-only bundler group, as described in this article. To make sure things were happening as expected, I both commented out the console-group-loading code in application.rb, and also renamed the bundler group to :consoleX. Much to my surprise, pry is still getting loaded when I fire up the rails console.
group :consoleX do
gem 'pry'
gem 'pry-doc'
gem 'awesome_print'
end
➔ bundle exec rails console Loading development environment (Rails 3.2.3) [1] pry(main)>
If I comment out the group completely, then pry is not loaded.
What’s going on here?
Because bundle will include all gems from all groups by default. To bundle without a specific group run:
This setting will be remembered until you change it, so any future calls to bundle install or update will be run without the excluded groups. See the bundler docs.
If you’re using Pry in place of IRB following the instructions from the Pry wiki this means that Pry will be used if it is available at all, and IRB only if it is not. So when you run the console with Pry in your bundle it gets called even if you ask for an environment you didn’t want it included in.
To fix this it has to not be in your bundle, then when you run
bundle exec rails consoleyou can use irb instead.If you want to switch back and forth between Pry and IRB more easily, I would recommend not monkeypatching Rails to use IRB instead of Pry. Just leave Pry in the group you want it and bundle normally (pry is in the bundle), and when you want to use Pry as your rails console call
pry -r ./config/environment. See the Railscast for an example.