From 12436c4aa9d32ae95562aaa13495378400171a70 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 29 Mar 2021 02:09:06 -0500 Subject: [PATCH] Fix IpAddressType autoload warning. Fix Rails complaining about IpAddressType not being reloaded by hot reloading: DEPRECATION WARNING: Initialization autoloaded the constant IpAddressType. Being able to do this is deprecated. Autoloading during initialization is going to be an error condition in future versions of Rails. Reloading does not reboot the application, and therefore code executed during initialization does not run again. So, if you reload IpAddressType, for example, the expected changes won't be reflected in that stale Class object. This autoloaded constant has been unloaded. 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. --- config/initializers/types.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/initializers/types.rb b/config/initializers/types.rb index de1ef4b05..38f86e36c 100644 --- a/config/initializers/types.rb +++ b/config/initializers/types.rb @@ -1 +1,3 @@ -ActiveRecord::Type.register(:ip_address, IpAddressType) +Rails.application.reloader.to_prepare do + ActiveRecord::Type.register(:ip_address, IpAddressType) +end