I have a module Foo::Bar, which extends ActiveRecord::Base with some
custom functionality. This module is in lib/foo/bar.rb. Inside this
file is also the code, that includes the module into
module Foo module Bar # stuff ... end end ActiveRecord::Base.send(:include, Foo::Bar)
Then, this file is required in config/initializers/foo.rb:
The problem is, that sometimes i get this nasty error:
A copy of Foo::Bar has been removed from the module tree but is
and I really can’t figure out what’s the problem. The weird thing is
that the error disappears when I restart the application, but
sometimes appears again on a different page. It looks completely
magical to me
Everything works fine in test and production environments, so this has
probably something to do with the Rails dependency loading/unloading
So, I guess I can make it into a plugin, but it’s really very simple
and quite specific to my application, so it’s not worth the effort.
That’s why I want to keep it only in lib.
Things I tried:
- Putting the lib/foo path into config.load_once_paths in config/
- adding unloadable to the Foo::Base module
- moving the include line (ActiveRecord::Base.send(:include, …) into
But nothing helps
Any help will be appreciated. Thanks.