2013-03-26 60 views
0

来自Box的Sinatra不允许单独的操作存档?就像这样:Sinatra和“控制器”行为

index.php 
    get '/' and other 

user.php 
get '/user/show/' 
post '/user/new/' and other 

怎么说的 '/用户/ *' 的要求,并为的index.php '/' 西纳特拉使用user.php的。 和许多看起来应用程序在一个文件中写入sinatra的帖子? (?一个巨大的屁股)

回答

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 
相关问题