An initialized constant error occurs in the production environment of rails5.
There are no errors in the development environment, and I am writing to inquire about the cause.
◆ Commands
#rails restart
# bundle exec rails runner [class name]. [method name] - eproduction
initialized constant Rails::Command::RunnerCommand::[Class Name]
「 If you run this command without "-e production", it will be successful.
※ Class Name is located under lib.
◆ Application.rb Settings
config.load_defaults 5.1
config.i18n.default_locale=:ja
config.autoload_paths+=Dir ["#{config.root}/lib/**/"]
config.eager_load_paths+=Dir["#{config.root}/lib/**/"]
config.paths.add 'lib', eager_load: true
Also, please let me know if there are any other parameters you need for analysis.
ruby-on-rails
In rails5+, eager_load_paths and auto_load_paths are assumed to be generated from config.paths on their own.
Therefore, only config.paths.add 'lib', eager_load:true
is needed, and I think it would be better to configure paths in this format only.
I probably solved it myself, so I will write down the answer as a reminder.
◆ application.rb (before modification)
config.load_defaults 5.1
config.i18n.default_locale=:ja
config.autoload_paths+=Dir ["#{config.root}/lib/**/"]
config.eager_load_paths+=Dir["#{config.root}/lib/**/"]
config.paths.add 'lib', eager_load: true
◆ application.rb (modified)
config.load_defaults 5.1
config.i18n.default_locale=:ja
#config.autoload_paths+=Dir["#{config.root}/lib/**/"]
config.eager_load_paths+=Dir["#{config.root}/lib/"]
config.paths.add 'lib', eager_load: true
The following three points were implemented.
※ Comment out autoload_paths (because it is deprecated in Rails5)
https://qiita.com/joooee0000/items/3ab0f3d791e0d0beb639
※ Modify "~lib/**/" in eager_load_paths to "~lib/"
※ Reboot Production
It is not clear at this time why this worked.
If anyone knows, please write it down.
356 I want to change the format (date and time display) of the legend in chronological order.
354 Understanding How to Configure Google API Key
352 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
363 Logging Out with the Application Load Balancer and Authentication Using Cognito
354 JSON.parse fails even though there is no problem with the format.
© 2023 OneMinuteCode. All rights reserved.