require'sinatra/base'# The controller for the home page.
classHomeController< ::Sinatra::Base
get '/'do # <-- (1) slash
"This is the home controller."endend# The controller for the documents section.
classDocumentsController< ::Sinatra::Base
get '/'do # <-- (2) no slash
"This is the documents controller."endend# The main application. It aggregates the different controllers using Rack::URLMap.
classApplicationdefinitialize@app=::Rack::URLMap.new('/'=>HomeController.new,'/documents'=>DocumentsController.new)enddefcall(env)@app.call(env)endend
run Application.new# 1. Load http://localhost:9292/
# You’ll see the home controller message.
## 2. Load http://localhost:9292/documents
# You’ll see the documents controller message.
## 3. Change "get ''" to "get '/'" and load http://localhost:9292/documents
# You’ll get a 404 error.