You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#269 Fix autoloading in zeitwerk mode
[@gburgett](https://watermark-dev.slack.com/team/U6U4QQ1UG)
merged 2022-09-02
* Switches to use `const_get` which works in both classic and zeitwerk mode.
* Added doc about a pitfall of Zeitwerk autoloading with app-defined model namespaces
Rails 6 introduced the Zeitwerk autoloader which uses a completely different technique to load application models. The technique no longer depends on `const_missing` and in fact that method no longer works when a rails application is in `:zeitwerk` mode.
Instead, Zeitwerk depends on [ruby's core "autoload" feature](https://ruby-doc.org/core-2.0.0/Module.html#method-i-autoload). It sets up the relationship between constants and files beforehand, instead of discovering them on-demand. The consequence of this is that `const_get` still works to get the constants, but Ruby (not Zeitwerk) auto-loads it on demand from the file. To the application, the constant exists regardless of whether it has been loaded or not.
More info: https://www.urbanautomaton.com/blog/2020/11/04/rails-autoloading-heaven/