Und*_*ion 7 ruby-on-rails bundler ruby-on-rails-3 gemfile
我在Heroku上设置遥控器进行制作和舞台演出.
在暂存时,我已将应用程序的env设置为包括:
RACK_ENV=staging
RAILS_ENV=staging
Run Code Online (Sandbox Code Playgroud)
我希望能够以我目前使用的相同方式指定staging我的组,或者:Gemfileproductiontestassets
group :staging do
gem "example", "~> 0.9"
end
Run Code Online (Sandbox Code Playgroud)
我了解如何添加自定义组.从我的application.rb:
groups = {
assets: %w(development test)
}
Bundler.require(:security, :model, :view, *Rails.groups(groups))
Run Code Online (Sandbox Code Playgroud)
但是,如何添加仅在暂存中加载的组?
我试过没有成功:
groups = {
assets: %w(development test),
staging: %(staging)
}
Bundler.require(:security, :model, :view, *Rails.groups(groups))
Run Code Online (Sandbox Code Playgroud)
Gle*_*enn 10
您的Gemfile可以包含如下组:
# Gemfile
group :staging do
gem 'example','~>1.0'
end
Run Code Online (Sandbox Code Playgroud)
为暂存创建环境
# /config/environments/staging.rb
...
copy config/environments/production.rb code here with adjustments as needed
...
Run Code Online (Sandbox Code Playgroud)
其工作原理可在/config/application.rb中找到.
Rails.groups包括:默认组(所有未组合的gems)和与RAILS_ENV设置的环境名称匹配的gem组,在本例中为"staging".你的要求.您的Bundler.require应如下所示:
Bundler.require *Rails.groups(:assets => %w(development test))
Run Code Online (Sandbox Code Playgroud)
有关Bundler和组的更多信息,请阅读http://bundler.io/v1.5/groups.html