.net and other musings

Ben Lovell, an agile developer living in the UK.

Sinatra: Matching routes with or without trailing slashes

leave a comment »

I felt compelled to post this as it took me more than a few minutes to figure this one out. Sinatra treats URLs with/without trailing slashes differently unless you append “/?” to the end of your route like so:

get "/test/?" do
    'in test'
end

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

Written by benl

April 17, 2009 at 3:07 pm

Posted in Ruby, Sinatra

Leave a Reply