I have a Rails initializer (features.rb
) that must access a model (Report
).
Report.all.each do |report|
default_to_enabled(report&.feature_name)
end
This all worked perfectly with Rails 6.1 using Zeitwerk and defaults set for 6.1:
config.load_defaults 6.1
config.autoloader = :zeitwerk
But upgrading to Rails 7, keeping defaults at 6.1 (and obviously using Zeitwerk), it is not working:
/Users/brandon/Code/Rails/portal/config/initializers/features.rb:105:in `<main>': uninitialized constant Report (NameError)
If I manually require
the Report
model, it doesn't solve the problem. Instead I just get
/Users/brandon/Code/Rails/portal/app/models/report.rb:1:in `<main>': uninitialized constant ApplicationRecord (NameError)
Did you mean? ApplicationConfig
So it seems like there's a whole lot of stuff that has not yet been loaded at this point in the Rails boot-up process, but which would have been loaded at this point running on Rails 6.1.
Adding require 'rails/all'
doesn't change anything.
(In case it's not obvious, this applies to all of my models, and lots of other things. None of the classes I have previously had available during initialization are now available on Rails 7.)
How can I fix this and make everything work on Rails 7?