title: How do I fix the error "Circular dependency detected while autoloading constant" on Heroku / Ruby
body: <p>I'm getting this error on Heroku after I deploy, but I'm not getting the error or experiencing problems with this locally.</p>
  
  <p>What is wrong with the following naming / namespacing, etc? What am I missing?</p>
  
  <p>models/concerns/purchase/finalize_utils.rb</p>
  
  <pre class="lang-ruby prettyprint-override"><code>module Purchase::FinalizeUtils
    extend ActiveSupport::Concern
  end
  </code></pre>
  
  <p>models/purchase.rb</p>
  
  <pre><code>class Purchase &lt; ActiveRecord::Base 
    include FinalizeUtils
  end
  </code></pre>
  
  <p>log error:</p>
  
  <pre><code>2017-01-26T22:39:25.553902+00:00 app[web.1]: RuntimeError: Circular dependency detected while autoloading constant Purchase::FinalizeUtils
  2017-01-26T22:39:25.553903+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:492:in `load_missing_constant'
  2017-01-26T22:39:25.553903+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184:in `const_missing'
  2017-01-26T22:39:25.553904+00:00 app[web.1]:   /app/app/models/purchase.rb:19:in `&lt;class:Purchase&gt;'
  2017-01-26T22:39:25.553904+00:00 app[web.1]:   /app/app/models/purchase.rb:16:in `&lt;top (required)&gt;'
  2017-01-26T22:39:25.553905+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
  2017-01-26T22:39:25.553906+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require'
  2017-01-26T22:39:25.553906+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
  2017-01-26T22:39:25.553907+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
  2017-01-26T22:39:25.553907+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:360:in `require_or_load'
  2017-01-26T22:39:25.553907+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:494:in `load_missing_constant'
  2017-01-26T22:39:25.553908+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184:in `const_missing'
  2017-01-26T22:39:25.553909+00:00 app[web.1]:   /app/app/models/concerns/purchase/finalize_utils.rb:1:in `&lt;top (required)&gt;'
  2017-01-26T22:39:25.553909+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
  2017-01-26T22:39:25.553909+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require'
  2017-01-26T22:39:25.553910+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
  2017-01-26T22:39:25.553910+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
  2017-01-26T22:39:25.553910+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:360:in `require_or_load'
  2017-01-26T22:39:25.553911+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:317:in `depend_on'
  2017-01-26T22:39:25.553912+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!'
  2017-01-26T22:39:25.553911+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:233:in `require_dependency'
  2017-01-26T22:39:25.553912+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:471:in `each'
  2017-01-26T22:39:25.553912+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:471:in `block in eager_load!'
  2017-01-26T22:39:25.553913+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:469:in `each'
  2017-01-26T22:39:25.553913+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:469:in `eager_load!'
  2017-01-26T22:39:25.553914+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/engine.rb:346:in `eager_load!'
  2017-01-26T22:39:25.553914+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application/finisher.rb:56:in `each'
  2017-01-26T22:39:25.553914+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application/finisher.rb:56:in `block in &lt;module:Finisher&gt;'
  2017-01-26T22:39:25.553915+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/initializable.rb:30:in `instance_exec'
  2017-01-26T22:39:25.553915+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/initializable.rb:30:in `run'
  2017-01-26T22:39:25.553915+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/initializable.rb:55:in `block in run_initializers'
  2017-01-26T22:39:25.553916+00:00 app[web.1]:   /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
  2017-01-26T22:39:25.553916+00:00 app[web.1]:   /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
  2017-01-26T22:39:25.553917+00:00 app[web.1]:   /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
  2017-01-26T22:39:25.553917+00:00 app[web.1]:   /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
  2017-01-26T22:39:25.553917+00:00 app[web.1]:   /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each'
  2017-01-26T22:39:25.553918+00:00 app[web.1]:   /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `call'
  2017-01-26T22:39:25.553918+00:00 app[web.1]:   /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
  2017-01-26T22:39:25.553918+00:00 app[web.1]:   /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
  2017-01-26T22:39:25.553919+00:00 app[web.1]:   /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
  2017-01-26T22:39:25.553921+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/initializable.rb:54:in `run_initializers'
  2017-01-26T22:39:25.553921+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.5.1/lib/rails/application.rb:352:in `initialize!'
  2017-01-26T22:39:25.553922+00:00 app[web.1]:   /app/config/environment.rb:11:in `&lt;top (required)&gt;'
  </code></pre>