LoginSignup
30

More than 5 years have passed since last update.

RailsのRAILS_ENVに自分の環境を追加する

Posted at

RailsのRAILS_ENVに自分の環境を追加する

Railsはデフォルトでproduction、development、testの3つの環境を切り替えて使えるようになっています。

自分のPCで開発する時と、ユーザー先のPCで開発する時で、
アプリが接続するサーバーのアドレスを変更したいことがあります。
(つまりdevelopment環境を2つ用意したい)

例えばdevelopment_userという環境名を用意したい場合、次のようにします。

  1. confg/environments/development_user.rbを用意します。

  2. config/database.ymldevelopment_user用の設定を追記します。

  3. Gemfileなど環境毎に変更している箇所にも設定や処理を追記します。

これで準備は出来たので、

$ bundle install
$ bundle exec rake db:migrate RAILS_ENV=development_user
$ bundle exec rails s -e development_user

といった形で切り替えられます。

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
30