2013-03-26 28 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 
相關問題