Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'sinatra/base'

# The controller for the home page.
class HomeController < ::Sinatra::Base

  get '/' do # <-- (1) slash
    "This is the home controller."
  end

end

# The controller for the documents section.
class DocumentsController < ::Sinatra::Base

  get '/' do # <-- (2) no slash
    "This is the documents controller."
  end

end

# The main application. It aggregates the different controllers using Rack::URLMap.
class Application

  def initialize
    @app = ::Rack::URLMap.new(
      '/'          => HomeController.new,
      '/documents' => DocumentsController.new
    ) 
  end

  def call(env)
    @app.call(env)
  end

end

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.