Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Forked from ajsharp/gist:1029827
Created June 16, 2011 18:19
Show Gist options
  • Save jacquescrocker/1029861 to your computer and use it in GitHub Desktop.
Save jacquescrocker/1029861 to your computer and use it in GitHub Desktop.
module Sinatra
module AmbiguousRoutes
module RouteWithAmbiguousPath
def route(verb, path, options={}, &block)
# don't modify routes that already defined with a format extension
case path
when Regexp
else
if path =~ /\..*$/
pth, _, ext = path.split(/(\.)(.*)$/)
path = /^#{pth}(\.#{ext}|)$/
else
path = /^#{path}(\.json|)$/
end
end
super(verb, path, options, &block)
end
end
def self.registered(app)
app.class_eval do
class << self
include RouteWithAmbiguousPath
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment