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
.
Stop referencing autoloaded classes from static files. If you can't, see workaround B and C.
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
Make sure you're not caching instances of the erroring class (e.g. with Thread.current
).
If possible, make the autoloaded class static by moving it out of Rails' load path.