Open Cardyard opened 2 years ago
Any code in a reusable action is not reloaded
They are not reloaded because the action need to be explicitly require
-ed and is not autoloaded with the current way.
So I want to think about the better way to handle custom actions, which is more friendly for autoloading.
The problem I had making a reusable action reloadable, is Zeitwerk unloads before reloading, and unloading a reusable action appears to remove it from the router. I'm happy with the way it works as the reusable actions should be kept simple, and any code held in services etc which are reloadable.
Is your feature request related to a problem? Please describe. It took me a while to get autoloading working with Zeitwerk and Rails 7 and Rails Admin 3.0. I've ended up with the opposite of what I had pre: Zeitwerk/Rails 7/Rails Admin 3.0..
Describe proposed solution(s) Add some comments to... Configuration 2. Actions
These are my proposed comments...
Reloading with Zeitwerk
If you are defining reusable rails_admin actions in zeitwerk mode(the only mode post Rails 6), you can include your library of code in the main autoloader in
config/application.rb
, but must register your rails_admin actions only once. This can be achieved using theafter_initialize
blockAvoid using
to_prepare
block as an alternative toafter_initialze
because theto_prepare
block will be run again after unloading classes by the autoloader which results in rails_admin actions and models being removed from the router.Note that
require
is discouraged as you should allow the autoloader to manage loading your code, and usingrequire
will exclude the required file from the autoloader. However, since rails_admin actions can't be reloaded, its fine/preferable to userequire
. Any code you wish to be reloadable can, of course, be placed in other files.