Fixing "A copy of Klass has been removed from the module tree but is still active"

Updated . Posted . Visible to the public.

This can happen during development when classes without automatic reloading are pointing to classes with automatic reloading. E.g. some class in lib is calling Model.static_method.

Workaround A

Stop referencing autoloaded classes from static files. If you can't, see workaround B and C.

Workaround B

Make sure the offending file (the one referencing the autoloaded class) is autoloaded, too. You may do this:

# config/application.rb

  config.paths.add 'offending/file/parent/directory', eager_load: true

Workaround C

Make sure you're not caching instances of the erroring class (e.g. with Thread.current).

Workaround D

If possible, make the autoloaded class static by moving it out of Rails' load path.

Henning Koch
Last edit
Dominik Schöler
Keywords
cache, classes, class
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2010-08-25 12:21)