Q:

Run multiple controllers inside a Rack map

Inside a modular Sinatra app, I have the following code in the config.ru file:
# ...
map '/' do
  run MyApp::Controller::WelcomesController
  run MyApp::Controller::Authenticated::Foo::HomesController
  run MyApp::Controller::Authenticated::Foo::SearchesController
end
# ...

And the controllers files, such as Homes controller:
# app/controllers/authenticated/foo/homes_controller.rb
require_relative 'base'
module MyApp
  module Controller
    module Authenticated
      module Foo
        class HomesController < Foo::Base
          get '/Users/Foos' do
            haml 'authenticated/foo/homes/show'.to_sym
          end
        end
      end
    end
  end
end

Searches controller:
# app/controllers/authenticated/foo/searches_controller.rb
require_relative 'base'
module MyApp
  module Controller
    module Authenticated
      module Foo
        class SearchesController < Student::Base
          get '/Users/Foos/Searches' do
            haml 'authenticated/foo/searches/index'.to_sym
          end

          get '/Users/Foos/Searches/:id' do
            haml 'authenticated/foo/searches/show'.to_sym
          end
        end
      end
    end
  end
end

Welcomes controller:
# app/controllers/welcomes_controller.rb
require_relative 'base'
module MyApp
  module Controller
    class WelcomesController < Base
      get '/' do
        haml 'welcomes/show'.to_sym, layout: false
      end
    end
  end
end

And I don't know why, but it seems that, there is a conflict between thoses controllers' routes.
If for instance I comment HomesController and SearchesController, then WelcomesController's routes are availables (200). But the routes of the two other controllers are inaccessible (404).
If I uncomment the 3 lines of the config.ru, only the routes of one of thoses 3 controllers are going to be availables.
Is there a tip to fix this trouble?  Thanks a lot!

A:

You only get one run per map. Add more maps, or you could try Rack::Cascade:
run Rack::Cascade.new([
  MyApp::Controller::WelcomesController, 
  MyApp::Controller::Authenticated::Foo::HomesController,
  MyApp::Controller::Authenticated::Foo::SearchesController,
])

As an aside, you don't win prizes for nesting namespaces - it's Ruby, not Java ;)

