title: How to fix / debug 'expected x.rb to define X.rb' in Rails
body: <p>I have seen this problem arise in many different circumstances and would like to get the best practices for fixing / debugging it on StackOverflow.</p>
  
  <p>To use a real world example this occurred to me this morning:</p>
  
  <pre><code>expected announcement.rb to define Announcement
  </code></pre>
  
  <p>The class worked fine in development, testing <em>and</em> from a production console, but failed from in a production Mongrel. Here's the class:</p>
  
  <pre><code>class Announcement &lt; ActiveRecord::Base
    has_attachment :content_type =&gt; 'audio/mp3', :storage =&gt; :s3
  end
  </code></pre>
  
  <p>The issue I would like addressed in the answers is not so much solving this specific problem, but how to properly debug to get Rails to give you a meaningful error as expected x.rb to define X.rb' is often a red herring...</p>
  
  <p><strong>Edit (3 great responses so far, each w/ a partial solution</strong>)</p>
  
  <p><strong>Debugging:</strong></p>
  
  <ol>
  <li><p>From Joe Van Dyk: Try accessing the model via a console on the environment / instance that is causing the error (in the case above: script/console production then type in 'Announcement'.</p></li>
  <li><p>From Otto: Try setting a minimal plugin set via an initializer, eg: config.plugins = [ :exception_notification, :ssl_requirement, :all ] then re-enable one at a time.</p></li>
  </ol>
  
  <p><strong>Specific causes:</strong></p>
  
  <ol>
  <li><p>From Ian Terrell: if you're using attachment_fu make sure you have the correct image processor installed. attachment_fu will require it even if you aren't attaching an image.</p></li>
  <li><p>From Otto: make sure you didn't name a model that conflicts with a built-in Rails class, eg: Request.</p></li>
  <li><p>From Josh Lewis: make sure you don't have duplicated class or module names somewhere in your application (or Gem list).</p></li>
  </ol>