开发者

Sinatra Routing Exceptions

开发者 https://www.devze.com 2022-12-22 18:14 出处:网络
I want to be able to do the following: get \'/:slug\' do haml :page end get \'/administration\' do haml :admin

I want to be able to do the following:

get '/:slug' do
  haml :page
end

get '/administration' do
  haml :admin
end

Is there a way that I can have get '/:slug' do have an exception for /administration? I reali开发者_运维问答ze you can do this with if else statements:

get '/:slug' do
  if params[:slug] == 'administration'
    haml :admin
  else
    haml :page
  end
end

But that isn't very clean looking. Is there a way to have an exception to routes?


Sinatra should respect the order of routes, so if you put /administration route first, and a request matches it, get '/:slug' won't be called at all.

0

精彩评论

暂无评论...
验证码 换一张
取 消