LoginSignup
1
2

More than 1 year has passed since last update.

【ざっくり解説】Railsで本番環境と開発環境の動作を分ける方法

Last updated at Posted at 2020-11-05

いきなり結論

Controllerの場合

本番環境

users_controller.rb
if Rails.env.production?
  #本番環境のみ適用
end

開発環境

users_controller.rb
if Rails.env.development?
  #開発環境のみ適用
end

Viewの場合

本番環境

index.html.erb
<% if Rails.env.production? %>
  <%# 本番環境のみ %>
<% end %>

開発環境

index.html.erb
<% if Rails.env.development? %>
  <%# 開発環境のみ %>
<% end %>

秒速でまとめ

「開発環境と本番環境でズレが出てしまう…」
「仕方なく本番環境に合わせてるけど、開発環境の時に不便だな…」

そんな時に使える条件分岐をご紹介しました。
本番環境って難しい!Rails学習頑張っていきましょう!

1
2
0

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
1
2