2011-01-08 74 views

回答

68

當然,加content_typebefore回調:

class MyApp < Sinatra::Base 

    before do 
    content_type 'application/json' 
    end 

    ... 

end 

Sinatra 1.1介紹模式匹配前置過濾器:

before '/admin/*' do 
    check_logged_in 
end 
+0

謝謝!我如何創建一個上下文,以便之前的過濾器僅適用於特定的一組路由,而不是全部? – ma11hew28 2011-01-08 03:18:52