Settings that should be done when operating a production environment with Rails

Make the error display on the browser the same in development and production environments

First, if an ERROR occurs in the development environment, detailed information will be displayed on the browser. 8c1d32d1432226f625cab33c2ed1fcc7.png However, in the production environment, even if some kind of ERROR occurs, "We're sorry, but something went wrong." Is displayed. picture_pc_f8886f63bd354c264487153ad2c5c567.png Therefore, to display detailed information on the browser even in the production environment You can change config.consider_all_requests_local = false to true.

config/environments/production.rb


config.consider_all_requests_local = true
References

Rails docs (https://railsdoc.com/page/config_consider_all_requests_local)

Reset DB in production environment

In the production environment of Rails 5 or later, a function to prevent the execution of DB-destroying commands such as db: drop and db: reset has been added. Therefore, even if you do bundle exec rake db: migrate: reset RAILS_ENV = production etc. in the production environment, an error will occur.

approach

You can specify DISABLE_DATABASE_ENVIRONMENT_CHECK = 1 in the environment variable.

$ bundle exec rake db:migrate:reset RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1
References

Rails5 production does not allow rake db: drop, normally

Settings under Rails config / environments that you should know

By reading through the following sites, you may find a clue to the solution when you get stuck in the production environment. Read under Rails config / environments

Recommended Posts

Settings that should be done when operating a production environment with Rails
[Rails] "pry-rails" that can be used when saving with the create method
Launching the production environment with docker + rails (ver5.2) and errors that occurred
A memorandum when building an environment with Ruby3.0 x Rails6.1 x Docker x CentOS Stream
Settings to be done when changing from Sublime Text to VScode (when writing Ruby On Rails)
Error memorandum that occurred when creating a CI / CD environment [Rails + CircleCI + Capistrano + AWS]
InterstitialAd implementation example (AdMob) that should never be done
When I personally developed with Rails, it was a painful story that Rails was hit very much
How to set environment variables when using Payjp with Rails
I made a development environment with rails6 + docker + postgreSQL + Materialize.
Create a page control that can be used with RecyclerView
Be careful of initialization timing when using MessageEncryptor with Rails 5.2 / 6.0
Options for rails new and settings to be done after rails new
[rails] Problems that cannot be registered / logged in with devise
[Docker] Rails 5.2 environment construction with docker
OkHttp3 should be a singleton
[Rails] Avoid SELECT issued when creating a model with belongs_to defined!
Can't output PDF in production environment (EC2, Amazon Linux) with Rails
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Spring should be suspected when Rails commands do not work properly
Note that Insert could not be done with Spring Data JDBC
Naming convention when creating a new controller or model with rails
[Rails] A memo that created an advanced search form with ransack
Mecab installation that can be done almost by typing a command
Steps to build a Ruby on Rails development environment with Vagrant
Rails tutorial When rails new cannot be done due to different versions
Pay.JP Solution when it can be done locally but it does not work well in the production environment