Reputation: 1861
In Rails application, in boot.rb
, there is a line:
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
In application.rb
, there is another line:
Bundler.require(:default, Rails.env)
Could you briefly explain what Rails / Bundler do at require 'bundler/setup'
and at 'Bundler.require'
?
Is it valid statement, that Bundler is required at bundler/setup
and all gems from Gemfile
are required at Bundler.require
?
Upvotes: 4
Views: 2044
Reputation: 5644
What require 'bundler/setup'
does is make Rails automatically discover the Gemfile and then add all the gems defined in it to Ruby's load path.
Bundler.require(:default, Rails.env)
will then require all the gems in the Gemfile depending on the current Rails environment. So if current environment is the development environment, Rails will load all gems that are meant to be used in the development environment.
Hope that helps!
Upvotes: 7