2014-01-05 27 views
4

在Rails應用程序,在boot.rb,有一行:什麼需要'bundler/setup'和'Bundler.require'呢?

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 

application.rb,還有另一條線:

Bundler.require(:default, Rails.env) 

您能否簡要解釋一下什麼軌道/捆紮機做在require 'bundler/setup''Bundler.require'

這是否是有效的陳述,需要Bundler在bundler/setupGemfile需要所有寶石Bundler.require

回答

6

require 'bundler/setup'所做的是讓Rails自動發現Gemfile,然後將其中定義的所有寶石添加到Ruby的加載路徑中。

Bundler.require(:default, Rails.env)將根據當前的Rails環境需要Gemfile中的所有寶石。因此,如果當前環境是開發環境,Rails將加載所有旨在用於開發環境的寶石。

希望有幫助!

+0

這就是我一直在尋找的!謝謝你,@Gjaldon! –

+0

很高興我有幫助! @AlexSmolov,請接受答案:) – Gjaldon

+0

這非常有幫助。非常感謝你。 –