Read more

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

Henning Koch
August 25, 2010Software engineer at makandra GmbH

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

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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.

Posted by Henning Koch to makandra dev (2010-08-25 14:21)