Can anyone explain me or give me a resource where I can learn the differences between rails console and bundle console? Is there way to load all the gems automatically in irb instead of require gem?
Here is a good explanation: What's the Difference Between irb
, bundle exec irb
, bundle console
, and rails console
?
irb is the basic Ruby console. It ignores your Gemfile, and only core Ruby classes are accessible without require-ing them. It can’t easily load gems that Bundler installs outside of RubyGems’ load path.
bundle exec irb is like irb, if you also required bundler/setup. You can only easily require gems that are in your Gemfile.lock, but you can load those gems no matter where Bundler put them.
bundle console is like bundle exec irb, if you also called Bundler.require. All of the gems in your Gemfile, except the ones marked require: false, can be used without requiring them. It’s really convenient when you’re writing your own gems, or working on non-Rails code.
rails console is like running bundle console inside a Rails app, if you also required config/environment.rb. You can play with your entire Rails app, autoloads and database connections work, and everything’s hooked up the way you’d expect. If you’re working in a Rails app, this is the most helpful kind of console.
The answer from Aleksandr is great.
I just wanted to add there is also the option for running
bundle exec rails console
which combines everything from rails console and bundle exec irb answer from Aleksandr's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With