Created
November 30, 2011 08:57
-
-
Save jamiehodge/1408464 to your computer and use it in GitHub Desktop.
Nested Sinatra resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
class Foo < Sinatra::Base | |
get '/' do | |
'foo' | |
end | |
get '/:id' do | |
params.inspect | |
end | |
end | |
class Routes < Sinatra::Base | |
get '/' do | |
'hello' | |
end | |
get '/biz/:biz_id/foo/?*' do | |
request.path_info =~ %r{^/biz/\d*?(/foo)(/.*)} | |
params.delete('splat') | |
Foo.call(env.merge! 'SCRIPT_NAME' => $1, 'PATH_INFO' => $2, 'rack.request.query_hash' => params) | |
end | |
run! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment