title: Rails: organizing models in subfolders having warning: toplevel constant A referenced by B::A
body: <p>Today I decided to reorganize big amount of user related models and I'm having a problem with it.</p>
  
  <p>Before I had such structure:</p>
  
  <pre><code>app/models/user.rb
  app/models/user_info.rb
  app/models/user_file.rb
  ...
  </code></pre>
  
  <p>So I moved all <code>user_</code> models to user subfolder like this:</p>
  
  <pre><code>app/models/user.rb
  app/models/user/info.rb
  app/models/user/file.rb
  ...
  </code></pre>
  
  <p>and changed their definitions to</p>
  
  <pre><code>class User::Info &lt; ActiveRecord::Base
  class User::File &lt; ActiveRecord::Base
  ...
  </code></pre>
  
  <p><code>User</code> model wasn't changed (except associations).</p>
  
  <p>Everything works fine except <code>User::File</code> model. When i'm trying to access this model i get the following error:</p>
  
  <pre><code>warning: toplevel constant File referenced by User::File
  </code></pre>
  
  <p>and indeed it returns standard ruby File class.</p>
  
  <p>What i'm doing wrong?</p>
  
  <p>UPD1:</p>
  
  <pre><code>root# rails c
  Loading development environment (Rails 3.2.13)
  2.0.0p195 :001 &gt; User::File
  (irb):1: warning: toplevel constant File referenced by User::File
   =&gt; File
  2.0.0p195 :002 &gt; User::Info
   =&gt; User::Info(...)
  </code></pre>
  
  <p>UPD2:</p>
  
  <pre><code>2.0.0p195 :001 &gt; User::SomeModel
  NameError: uninitialized constant User::SomeModel
  2.0.0p195 :002 &gt; User::IO
  (irb):2: warning: toplevel constant IO referenced by User::IO
   =&gt; IO 
  2.0.0p195 :003 &gt; User::Kernel
  (irb):3: warning: toplevel constant Kernel referenced by User::Kernel
   =&gt; Kernel 
  </code></pre>
  
  <p>My app doesn't have any IO or Kernel classes, except ruby default.</p>
  
  <p>UPD3:</p>
  
  <pre><code># app/models/user.rb
  class User &lt; ActiveRecord::Base
    has_many :files, class_name: 'User::File'
    ..
  end
  
  # app/models/user/file.rb
  class User::File &lt; ActiveRecord::Base
    belongs_to :user
    # some validations, nothing serious
  end
  </code></pre>