来自Box的Sinatra不允许单独行动提交?像这样:
index.php
get '/' and other
user.php
get '/user/show/'
post '/user/new/' and other
怎么说sinatra使用user.php作为'/ user / *'请求,使用index.php作为'/'。 如何看待许多应用程序在一个用sinatra编写的文件中发布? (一个巨大的屁股?)
答案 0 :(得分:0)
经过大量阅读后,存在一些解决方案:
1
class Get < Sinatra::Base
get('/') { 'GET!' }
end
class Post < Sinatra::Base
post('/') { 'POST!' }
end
class Routes < Sinatra::Base
get('/') { Get.call(env) }
post('/') { Post.call(env) }
end
run Routes
2
class Foo < Sinatra::Base
get('/foo') { 'foo' }
end
class Bar < Sinatra::Base
get('/bar') { 'bar' }
end
Routes = Rack::Mount::RouteSet.new do |set|
set.add_route Foo, :path_info => %r{^/foo$}
set.add_route Bar, :path_info => %r{^/bar$}
end
run Routes