Bundler如何知道使用什么环境?

Eri*_*rik 20 ruby-on-rails bundler ruby-on-rails-3

这可能是Bundler上一个非常"新手"的问题,但我想知道bundle install如何知道使用什么环境或如何设置它?或者我甚至需要?我的问题是我按环境分组我的宝石(在Gemfile中),现在部署我只想安装生产宝石.

Sim*_*tti 29

application.rb文件的顶部,您可以看到

# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
Run Code Online (Sandbox Code Playgroud)

启动Rails时,Bundler会自动加载:default组和当前环境的所有依赖项.

请注意,在运行时bundle install,Bundler会解析并安装所有环境的依赖项,除非您指定了--without option

$ bundle install --without staging development test
Run Code Online (Sandbox Code Playgroud)

在生产中,您可能还想添加--deployment标志.

有关bundle install的更多信息.


小智 0

您可以在 gem 深度声明中使用“group”选项。检查此 ASCIICast:http://asciicasts.com/episodes/201-bundler