title: Where do you put your Rack middleware files and requires?
body: <p>I'm in the process of refactoring some logic built into a Rails application into middleware, and one annoyance I've run into is a seeming lack of convention for where to put them.</p>
  
  <p>Currently I've settled on <code>app/middleware</code> but I could just as easily move it to <code>vendor/middleware</code> or maybe <code>vendor/plugins/middleware</code>...</p>
  
  <p>The biggest problem is having to require the individual files at the top of <code>config/environment.rb</code></p>
  
  <pre><code>require "app/middleware/system_message"
  require "app/middleware/rack_backstage"
  </code></pre>
  
  <p>or else I get uninitialized constant errors on the <code>config.middleware.use</code> lines. That could get messy very quickly. I'd rather this was tucked away in an initializer somewhere.</p>
  
  <p>Is there a conventional place to put this stuff?</p>
  
  <hr>
  
  <p>The specific answer I'm looking for with this bounty is: <strong>where can I put the require lines so that they are not cluttering the environment.rb file but still get loaded before the config.middleware.use calls?</strong> Everything I have tried leads to uninitialized constant errors.</p>
  
  <hr>
  
  <p><strong>Update</strong>: Now that we're using Rails 3.0, I treat a Rails app like any other Rack app; code files for middleware go in <code>lib</code> (or a gem listed in <code>Gemfile</code>) and are required and loaded in <code>config.ru</code>.</p>