Autoloading (and re-loading) generally works fine in my Ruby (
2.3.0) on Rails (
5.0.1) project. However, in development mode I occasionally see an error like the following:
Unable to autoload constant Foo::Bar, expected /app/models/foo/bar.rb to define it
This is unexpected because:
- The first request worked fine (it autoloaded once already).
- It only appears after editing code and sending a new request.
- It does not always happen. I cannot figure out why sometimes it fails to reload.
- The file (
foo/bar.rb) does, in fact, define
Moreover, the code for
foo/bar.rb is dead simple:
module Foo class Bar < CustomRecord end end
The simple work-around is to restart the server and then send the request again (which always succeeds). FWIW, I'm using
My best-guess is that something is not being reloaded, but I'm not sure how to go about debugging. I can't seem to point to any specific action which causes the problem. Sometimes editing code causes it to happen, sometimes not.