2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

productionで動かしながら、サーバーによって専用Gemを追加

Last updated at Posted at 2021-02-17

Stagingを構築する場合でもRails.envを変更しないことがよいとされています。
config/environments/staging.rb はアンチパターン!
Stagingでテストデータを作りたいとき、ベタ書きでSeedを作ろうとしましたが、メンテナンス性を考えFactoryBotで実装する方法を示します。

Stagingだけ読み込みたいGemがある例

group :development, :test do
  gem 'factory_bot_rails', group: :staging
  gem 'ffaker', group: :staging
end

本番サーバー

bundle install --without development test staging

stagingサーバー

bundle install --without development test
require 'factory_bot'
10.times { FactoryBot.create(:user) }

Herokuだけ読み込みたいGemがある例

app.json

{
  "env": {
    "RAILS_GROUPS": {
      "value": "heroku"
    }
  }
}

Gemfile

source 'https://rubygems.org'

group :heroku do
  gem 'rails_12factor'
end

参考

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?