title: What's a good way to require a whole directory tree in Rails?
body: <p>I am using Rails 3.2.2 and want to load all the code in a certain directory recursively. For example:</p>
  
  <pre><code>[Rails root]/lib/my_lib/my_lib.rb
  [Rails root]/lib/my_lib/subdir/support_file_00.rb
  [Rails root]/lib/my_lib/subdir/support_file_01.rb
  ...    
  </code></pre>
  
  <p>Based on Googling, I tried:</p>
  
  <pre><code>config.autoload_paths += ["#{Rails.root.to_s}/lib/my_lib/**"]
  config.autoload_paths += ["#{Rails.root.to_s}/lib/my_lib/**/"]
  config.autoload_paths += ["#{Rails.root.to_s}/lib/my_lib/**/*"]
  config.autoload_paths += ["#{Rails.root.to_s}/lib/my_lib/{**}"]
  config.autoload_paths += ["#{Rails.root.to_s}/lib/my_lib/{**}/"]
  </code></pre>
  
  <p>None of these load any of the code and I get "uninitialized constant" errors.</p>
  
  <p>This loads files directly in <code>/my_lib/</code>, but not subdirectories:</p>
  
  <pre><code>config.autoload_paths += ["#{Rails.root.to_s}/lib/my_lib"]
  </code></pre>
  
  <hr>
  
  <p>UPDATE</p>
  
  <p>Thanks for the comments.</p>
  
  <p>I put this in my <code>application.rb</code>:</p>
  
  <pre><code>Dir["#{Rails.root.to_s}/lib/**/*.rb"].each { |file| config.autoload_paths += [file] }
  </code></pre>
  
  <p>The application launches but classes declared in my library are not available:</p>
  
  <pre><code>&gt; MyClass
  NameError: uninitialized constant MyClass
  </code></pre>