From 838d3f73ddd4b333295b7cd942505ce775d03ee0 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 17 May 2020 10:12:15 +0200 Subject: [PATCH] The warning for autoloaded constants on boot includes a solution --- railties/lib/rails/application/finisher.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 85829ba8009..462e633b253 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -60,7 +60,18 @@ module Rails #{unload_message} - Please, check the "Autoloading and Reloading Constants" guide for solutions. + In order to autoload safely at boot time, please wrap your code in a reloader + callback this way: + + Rails.application.reloader.to_prepare do + # Autoload classes and modules needed at boot time here. + end + + That block runs when the application boots, and every time there is a reload. + For historical reasons, it may run twice, so it has to be idempotent. + + Check the "Autoloading and Reloading Constants" guide to learn more about how + Rails autoloads and reloads. WARNING end