PaygeVii
PaygeVii

Reputation: 37

Sinatra not matching any urls?

I'm trying to get Sinatra up and running with Ruby with some beginner tutorials. Sinatra works fine on '/' requests, but any extension to that seems to break it and returns the error message 'Sinatra doesn’t know this ditty.' It doesn't seem to matter what I put after the '/xxx', it all fails.

Here's my code, config.ru:

require 'sinatra'
get '/' do
  "Root"
end
get "/hello" do
    "hello"
end

Here's what the server is saying:

127.0.0.1 - - [14/Oct/2014 20:20:53] "GET / HTTP/1.1" 200 10 0.0016
127.0.0.1 - - [14/Oct/2014 20:20:57] "GET /hello HTTP/1.1" 404 442 0.0010
127.0.0.1 - - [14/Oct/2014 20:20:57] "GET /__sinatra__/404.png HTTP/1.1" 304 - 0.0017

Thanks for any help!

Upvotes: 0

Views: 269

Answers (1)

Nirav Gandhi
Nirav Gandhi

Reputation: 2005

A wild guess that your request url might have a trailing slash.

Sinatra treats URLs with/without trailing slashes differently unless you append “/?” to the end of your route like so:

get "/hello/?" do
  'hello'
end

The route specified above will match both “/hello and “/hello/”.

Upvotes: 0

Related Questions