title: Trouble on routing Racks
body: <p>I am using Ruby on Rails 3 and I would like to route some URLs to some Rack middlewares. That is, if a user try to browse at <code>http://&lt;my_site_name&gt;.com/api/user/1</code> the system should consider to run before a Rack file and then proceed in the request.</p>
  
  <p>I have a Rack::Api:User located in the <code>lib/rack/api/user</code> folder. </p>
  
  <p>From the RoR official documentation I discovered this:</p>
  
  <blockquote>
  <pre><code>     Mount a Rack-based application to be used within the application.
  
         mount SomeRackApp, :at =&gt; "some_route"
  
       Alternatively:
  
         mount(SomeRackApp =&gt; "some_route")
  
       All mounted applications come with routing helpers to access them.
       These are named after the class specified, so for the above example
       the helper is either +some_rack_app_path+ or +some_rack_app_url+.
       To customize this helper's name, use the +:as+ option:
  
         mount(SomeRackApp =&gt; "some_route", :as =&gt; "exciting")
  
       This will generate the +exciting_path+ and +exciting_url+ helpers
       which can be used to navigate to this mounted app.
  </code></pre>
  </blockquote>
  
  <p>In the routers.rb file I tryed</p>
  
  <pre><code>mount "Rack::Api::User", :at =&gt; "/api/user/1"
  # =&gt; ArgumentError missing :action
  
  scope "/api/user/1" do
    mount "Rack::Api::User"
  end
  # =&gt; NoMethodError undefined method `find' for "Rack::Api::User
  </code></pre>
  
  <p>I also tryed</p>
  
  <pre><code>match '/api/user/1' =&gt; Rack::Api::User
  # =&gt; Routing Error No route matches "/api/user/1"
  
  match '/api/user/1', :to =&gt; Rack::Api::User
  # ArgumentError missing :controller
  </code></pre>
  
  <p>but no one works.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>My Rack file is something like this:</p>
  
  <pre><code>  module Api
      class User
  
        def initialize(app)
          @app = app
        end
  
        def call(env)
          if env["PATH_INFO"] =~ /^\/api\/user\/i
            ...
          else
            @app.call(env)
          end
        end
      end
   end
  </code></pre>