title: Routing to different controllers having same name at different locations
body: <p>I am using Rocket_Pants gem to provide API access for my existing Rails app. I have two of controllers with the same name but stored in different locations:</p>
  
  <p>I store the controller that handles HTTP requests in <code>app/controllers</code>, and the controller that handles API calls in sub-directory <code>API</code> of <code>app/controllers</code>.</p>
  
  <p>I have the following in my Routes:</p>
  
  <pre><code>  # HTTP routing 
    resources :posts do
      collection do
        get 'search'
      end
    end
  
    # API routing
    api :version =&gt; 1 do
      resources :posts, :only =&gt; [:index, :show]
      resources :posts do
        collection do
          get 'search'
        end
      end
    end
  </code></pre>
  
  <p>However, when I <code>rake routes</code>, I got:</p>
  
  <pre><code>GET    /:version/posts/search(.:format)       posts#search {:version=&gt;/(1)/, :format=&gt;"json"}
  GET    /:version/posts(.:format)              posts#index {:version=&gt;/(1)/, :format=&gt;"json"}
  GET    /:version/posts/:id(.:format)          posts#show {:version=&gt;/(1)/, :format=&gt;"json"}
  </code></pre>
  
  <p>This means that my API routes are actually pointing to http controller and not API controller. How can I point my API routes to <code>API/posts#search</code> instead?</p>