Skip to content

Instantly share code, notes, and snippets.

@seak0503
Last active August 29, 2015 14:16
Show Gist options
  • Save seak0503/b35539d3928a1ab7631e to your computer and use it in GitHub Desktop.
Save seak0503/b35539d3928a1ab7631e to your computer and use it in GitHub Desktop.
Railsの3つの環境を使いこなす

Railsの3つの環境を使いこなす

Railsにはテスト環境(test)、開発環境(development)、本番環境(production)の 3つの環境がデフォルトで装備されています。

railsコマンドのconsoleservermigrateの3つでそれぞれ デフォルトの環境以外を指定する方法が異なり、混乱することがあるので まとめておきます。

console (default: development)

  • 構文: rails console [環境名]

  • 使用例: rails console test

server (default: development)

  • 構文: rails server --environment [環境名]

  • 使用例: rails server --environment production

migrate (default: development)

  • 構文: rake db:migrate RAILS_ENV=[環境名]

  • 使用例: rake db:migrate RAILS_ENV=production

assets precompile

  • 構文: rake assets:precompile RAILS_ENV=[環境名]

  • 使用例: rake assets:precompile RAILS_ENV=production

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment