I want to display a selection list of MyModel subclasses in a view. It's not working yet, so for sanity checking, I included this in my view:
<%= MyModel.descendants %>
The first time I render this page after re-starting the server, it shows the list of descendants (there are six). All subsequent times, it shows up as an empty list []
.
FWIW, I have a require
statement in my initializers:
Dir[Rails.root.join("app/models/my_models/**/*.rb").to_s].each {|f| require f}
... and I've verified that they're getting required.
What the @($%& is going on?
I had the same problem. Solved it by adding a config/initializers/preload_models.rb
with:
Dir[Rails.root + 'app/models/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize }
Hope that helps somebody.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With