Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between rails console and bundle console?

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?

like image 393
Kranthi Avatar asked Nov 18 '14 17:11

Kranthi


2 Answers

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.

like image 188
Aleksandr K. Avatar answered Oct 27 '22 00:10

Aleksandr K.


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.

like image 36
apadana Avatar answered Oct 26 '22 23:10

apadana