title: Why does Ruby on Rails spuriously raise "Unable to Autoload Constant" after editing code?
body: <p>Autoloading (and re-loading) generally works fine in my Ruby (<code>2.3.0</code>) on Rails (<code>5.0.1</code>) project. However, in development mode I occasionally see an error like the following:</p>
  
  <blockquote>
    <p>Unable to autoload constant Foo::Bar, expected /app/models/foo/bar.rb to define it</p>
  </blockquote>
  
  <p>This is unexpected because:</p>
  
  <ol>
  <li>The first request worked fine (it autoloaded once already). </li>
  <li>It only appears after editing code and sending a new request.</li>
  <li>It does not always happen. I cannot figure out why <em>sometimes</em> it fails to reload.</li>
  <li>The file (<code>foo/bar.rb</code>) does, in fact, define <code>Foo::Bar</code>.</li>
  </ol>
  
  <p>Moreover, the code for <code>foo/bar.rb</code> is dead simple:</p>
  
  <pre><code>module Foo
    class Bar &lt; CustomRecord
    end
  end
  </code></pre>
  
  <p>The simple work-around is to restart the server and then send the request again (which always succeeds). FWIW, I'm using <a href="https://github.com/burke/zeus" rel="noreferrer"><code>zeus server</code></a>.</p>
  
  <p>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.</p>