Skip to content

Instantly share code, notes, and snippets.

@ajsharp
Created June 16, 2011 17:59
Show Gist options
  • Save ajsharp/1029827 to your computer and use it in GitHub Desktop.
Save ajsharp/1029827 to your computer and use it in GitHub Desktop.
module Sinatra
module AmbiguousRoutes
def self.registered(app)
app.class_eval do
class << self
private
def route_with_ambiguity(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
route_without_ambiguity(verb, path, options, &block)
end
# alias_method :route_without_ambiguity, :route
# alias_method :route, :route_with_ambiguity
alias_method_chain :route, :ambiguity
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment