The warning for autoloaded constants on boot includes a solution

This commit is contained in:
Xavier Noria 2020-05-17 10:12:15 +02:00
parent 524d678a03
commit 838d3f73dd
1 changed files with 12 additions and 1 deletions

View File

@ -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