I have an engine that extends the Engine classes in its initializers like this:
module MyApp class Engine < ::Rails::Engine initializer 'extend Product' do AnotherApp::Product.send :include, MyApp::ProductExtender end end end
The ProductExtender module calls some methods in the AnotherApp :: Product file when it is enabled, for example
module ProductExtender def self.included( model ) model.send :include, MethodsToCall end module MethodsToCall def self.included( m ) m.has_many :variations end end end
This works in test and production environments, but when config.cache_classes = false it throws me a NoMethodError when I try to call something specific ProductExtender like @ product.variations.
Needless to say, itβs cold to see that all my tests pass, and then slam shut with a development error. This does not happen when I set cache_classes = true , but it makes me wonder if I am doing something that I should not be.
My question is twofold: Why is this happening, and is there a better way to achieve this functionality of extension / call methods for another application object?
Thanks everyone!
source share