How the routes are sequenced in Sinatra if we alias the methods?
Routes selection is different in sinatra then in rails. In rails routes.rb file is scanned top to bottom and first matching route is selected.
Sinatra associates routes with each method, in this scena开发者_如何学运维rio how the routes are selected if two methods are aliased.
Sinatra routing system is very versatile.
You can use method pass to jump routes. check out here [ http://www.sinatrarb.com/intro ]
get '/guess/:who' do
pass unless params[:who] == 'Frank'
'You got me!'
end
get '/guess/*' do
'You missed!'
end
regards
Unlike Ramaze actions—for which this question might make sense—Sinatra's routes are not defined by the presence of methods. Rather, you use methods to define the routes, and the order in which you call those methods partially defines the route priority.
For example, you write:
get "/" do
"Welcome!"
end
get "/products" do
"We sell stuff!"
end
There are no custom "index" or "products" methods to alias. For more information, see The Sinatra Book online.
精彩评论