What is the correct way to add: staging group in My Gemfile

I have remotes created on Heroku for production and production.

During the installation process, I installed the envs application to include:

RACK_ENV=staging RAILS_ENV=staging 

I would like to be able to specify the staging group in my Gemfile in the same way that I can currently use production , test or assets :

 group :staging do gem "example", "~> 0.9" end 

I understand how to add user groups. From my application.rb :

  groups = { assets: %w(development test) } Bundler.require(:security, :model, :view, *Rails.groups(groups)) 

But how to add a group that only loads in stage?

I tried without success:

  groups = { assets: %w(development test), staging: %(staging) } Bundler.require(:security, :model, :view, *Rails.groups(groups)) 
+6
source share
1 answer

Your gemfile may include a group as follows:

 # Gemfile group :staging do gem 'example','~>1.0' end 

Create an environment to host

 # /config/environments/staging.rb ... copy config/environments/production.rb code here with adjustments as needed ... 

The reason this works is in /config/application.rb.

Rails.groups includes: the default group (all ungrouped gems) and the gem group corresponding to the name of the environment specified by RAILS_ENV, which in this case will be "intermediate". Your requirement. Your Bundler.require request should look like this:

 Bundler.require *Rails.groups(:assets => %w(development test)) 

Read more about Bundler and groups at http://bundler.io/v1.5/groups.html

+9
source

Source: https://habr.com/ru/post/957081/


All Articles