Railsにはテスト環境(test)、開発環境(development)、本番環境(production)の 3つの環境がデフォルトで装備されています。
railsコマンドのconsole
、server
、migrate
の3つでそれぞれ
デフォルトの環境以外を指定する方法が異なり、混乱することがあるので
まとめておきます。
-
構文:
rails console [環境名]
-
使用例:
rails console test
-
構文:
rails server --environment [環境名]
-
使用例:
rails server --environment production
-
構文:
rake db:migrate RAILS_ENV=[環境名]
-
使用例:
rake db:migrate RAILS_ENV=production
-
構文:
rake assets:precompile RAILS_ENV=[環境名]
-
使用例:
rake assets:precompile RAILS_ENV=production