title: Rails 4: auto load from lib
body: <p>I'm trying to figure out the auto load thing, but I'm having a hard time making it to work without explicitly requiring the file.</p>
  
  <p>Do I need to make some special configuration so that Rails 4 would be able to auto load files inside <code>lib</code> directory?</p>
  
  <p>If I go to <code>rails console</code> and type <code>$LOAD_PATH</code> I'm able to see that <code>/home/some_user/workspace/rails/myapp/lib</code> is include into load path. This should mean that Rails will be able to auto load correct file?</p>
  
  <p>So as I understand:<br>
  if I would place my files inside <code>lib/</code> directory and I would use the naming conventions, Rails should be able to automatically require the correct file if anywhere in my code I would do something like this:</p>
  
  <p><code>cats = Cats::SomeCat.new</code> (given that <code>lib/cats/some_cat.rb</code> exists)</p>
  
  <p>and the <code>some_cat.rb</code> contains:</p>
  
  <pre><code>module Cats
      class SomeCat
          def initialize
              @name = "Some cat"
          end
     end
  end
  </code></pre>
  
  <p>However, Rails will show me error <code>uninitialized constant CatController::Cats</code>.</p>
  
  <p>If I add a line <code>require 'cats/some_cat'</code> everything will work. However, in 'The Rails 4 Way' I'm reading that :<br>
   <code>The bottom line is that you should rarely need to explicitly load Ruby code in your Rails application (using require) if you follow the naming conventions</code>.</p>
  
  <p>Am I using the wrong naming conventions or am I forced to use that<br>
  <code>config.autoload_paths += %W(#{config.root}/lib)</code> thing?</p>