I have remotes set up on Heroku for production and staging.
On staging I have set the app's envs to include:
RACK_ENV=staging
RAILS_ENV=staging
I would like to be able to specify a staging
group in my Gemfile
in the same way I can currently use production
, test
or assets
:
group :staging do
gem "example", "~> 0.9"
end
I understand how to add custom groups. From my application.rb
:
groups = {
assets: %w(development test)
}
Bundler.require(:security, :model, :view, *Rails.groups(groups))
But how do I add a group that is only loaded in staging?
I've tried without success:
groups = {
assets: %w(development test),
staging: %(staging)
}
Bundler.require(:security, :model, :view, *Rails.groups(groups))
Important! Gemfile. lock is automatically generated when you run bundle install or bundle update . It should never be edited manually.
You can (and should) specify versions of gems in your Gemfile but without the Gemfile. lock being included in Git. Then nobody else will get to benefit from your work of checking that the updated Gems still work. You should check your Gemfile for updates frequently and bundle update where appropriate.
Gemfiles require at least one gem source, in the form of the URL for a RubyGems server. Generate a Gemfile with the default rubygems.org source by running bundle init . If you can, use https so your connection to the rubygems.org server will be verified with SSL.
Your Gemfile could include a group as follows:
# Gemfile
group :staging do
gem 'example','~>1.0'
end
Create an environment for staging
# /config/environments/staging.rb
...
copy config/environments/production.rb code here with adjustments as needed
...
The reason this works is found in /config/application.rb.
Rails.groups includes the :default group (all ungrouped gems) and the gem group matching the name of the environment, set by RAILS_ENV, which in this case would be "staging". Your require. Your Bundler.require should look like:
Bundler.require *Rails.groups(:assets => %w(development test))
For more info regarding Bundler and groups, read http://bundler.io/v1.5/groups.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With