On Mar 1, 12:12 pm, Adam Cigánek <[email protected]> wrote: > Hey guys, > > 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 > ActiveRecord::Base: > > module Foo > module Bar > # stuff ... > end > end > > ActiveRecord::Base.send(:include, Foo::Bar) > > Then, this file is required in config/initializers/foo.rb: > > require 'foo/bar' > > The problem is, that sometimes i get this nasty error: > > A copy of Foo::Bar has been removed from the module tree but is > still active! > > 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 :) >
What happens is that your app loads and serves the first request fine. Then rails unloads unloadable code. When the next request arrives, ActiveRecord::Base, which isn't reloadable now has the dead module included. Only development uses this way of loading classes > - Putting the lib/foo path into config.load_once_paths in config/ > environment.rb This should work. You do (if my memory is correct) need to use absolute paths though - check what's already in ActiveSupport::Dependencies.load_once_paths Fred > - adding unloadable to the Foo::Base module > - moving the include line (ActiveRecord::Base.send(:include, ...) into > config/initializers/foo.rb > > But nothing helps :( > > Any help will be appreciated. Thanks. > > adam. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

