[RUBY] [Rough explanation] How to separate the operation of the production environment and the development environment with Rails

Sudden conclusion

For controller

Production environment

users_controller.rb


if Rails.env.production?
  #The definition of the production environment
end

Development environment

users_controller.rb


if Rails.env.development?
  #Definition of development environment
end

For views

Production environment

erb:index.html.erb


<% if Rails.env.production? %>
  <%#It is a display of the production environment%>
<% end %>

Development environment

erb:index.html.erb


<% if Rails.env.development? %>
  <%#It is a display of the production environment%>
<% end %>

Summary in seconds

"There is a gap between the development environment and the production environment ..." "I have no choice but to match it to the production environment, but it's inconvenient in the development environment ..."

We have introduced conditional branching that can be used in such cases. The production environment is difficult! Let's do our best to learn Rails!

Recommended Posts

[Rough explanation] How to separate the operation of the production environment and the development environment with Rails
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications
[Rails] How to delete production environment MySQL data after putting it in the development environment
How to build Rails, Postgres, ElasticSearch development environment with Docker
[Rails] How to get the URL of the transition source and redirect
[Rails] How to introduce kaminari with Slim and change the design
How to install Pry after building Rails development environment with Docker
[Rails] How to reset the database in production environment (Capistrano version)
How to build Rails 6 environment with Docker
How to decorate the radio button of rails6 form_with (helper) with CSS
How to execute with commands of normal development language in Docker development environment
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Launching the production environment with docker + rails (ver5.2) and errors that occurred
How to solve the local environment construction of Ruby on Rails (MAC)!
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Rails6.0 ~ How to create an eco-friendly development environment
Rails development environment created with VSCode and devcontainer
How to build API with GraphQL and Rails
[Rails] How to build an environment with Docker
Docker the development environment of Ruby on Rails project
[Rails] How to change the column name of the table
How to build Java development environment with VS Code
[Rails] How to get the contents of strong parameters
How to boot by environment with Spring Boot of Maven
Roughly the flow of web application development with Rails.
Environment construction method and troubleshooter at the time of joint development (rails, docker and github)
How to install Docker in the local environment of an existing Rails application [Rails 6 / MySQL 8]
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
How to set the retry limit of sidekiq and notify dead queues with slack
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~
What to do when ‘Could not find’ in any of the sources appears in the development environment with Docker × Rails × RSpec
How to set environment variables when using Payjp with Rails
[With back tricks] How to introduce React to the simplest Rails
How to set and describe environment variables using Rails zsh
Let's summarize how to extend the expiration date of Rails
[Rails] How to display the list of posts by category
How to run React and Rails on the same server
How to check the extension and size of uploaded files
How to deal with different versions of rbenv and Ruby
How to manage the difference in each environment with yml without increasing the number of RAILS_ENV
Comparison of WEB application development with Rails and Java Servlet + JSP
[Rails] How to execute "rails db: create" etc. in production environment EC2
[Docker] How to back up and restore the DB data of Rails application on docker-compose [MySQL]
[Swift5] How to get an array and the complement of arrays
How to set the IP address and host name of CentOS8
Explanation of the order of rails routes
How to make an application with ruby on rails (assuming that the environment has been built)
[Webpacker] Summary of how to install Bootstrap and jQuery in Rails 6.0
I tried to build the environment of PlantUML Server with Docker
Super beginner builds Rails6 + Postgresql environment with Docker to the end
Basics of Java development ~ How to write programs (variables and types) ~
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku
How to build an environment with Docker, which is the minimum required to start a Rails application
[Rails] How to omit the display of the character string of the link_to method
[Rails] How to change the page title of the browser for each page
How to delete large amounts of data in Rails and concerns
How to install the language used in Ubuntu and how to build the environment
I tried to check the operation of gRPC server with grpcurl
[Rails] Read the RSS of the site and return the contents to the front
I tried to take a look at the flow of Android development environment construction with Android Studio
How to get along with Rails