В этом приложении время выполнения ответа зависит от порядка маршрута.
app.rb:
class ProductsController < Sinatra::Base
get '/products/:id/presentation/:presentation_id' do
puts "/products/:id/presentation/params: #{params[:id]}, #{params[:presentation_id]}"
end
get '/products/:id/presentation/new' do
puts "/products/:id/presentation/new params: #{params[:id]}"
end
end
Запросы
curl localhost:9292/products/1/presentation/1
curl localhost:9292/products/1/presentation/new
Ответы
CONTROLLER_1 params: 1, 1
127.0.0.1 - - [22/Oct/2019:14:55:21 -0300] "GET /products/1/presentation/1 HTTP/1.1" 200 - 0.0039
CONTROLLER_1 params: 1, new
127.0.0.1 - - [22/Oct/2019:15:00:58 -0300] "GET /products/1/presentation/new HTTP/1.1" 200 - 0.0005
Если я изменяю (меняю) маршрутные заказы, я получаю другой результат:
app.rb:
class ProductsController < Sinatra::Base
get '/products/:id/presentation/new' do
puts "CONTROLLER_2 params: #{params[:id]}"
end
get '/products/:id/presentation/:presentation_id' do
puts "CONTROLLER_1 params: #{params[:id]}, #{params[:presentation_id]}"
end
end
Запросы:
curl localhost:9292/products/1/presentation/1
curl localhost:9292/products/1/presentation/new
Ответы:
CONTROLLER_1 params: 1, 1
127.0.0.1 - - [22/Oct/2019:15:06:06 -0300] "GET /products/1/presentation/1 HTTP/1.1" 200 - 0.0042
CONTROLLER_2 params: 1
127.0.0.1 - - [22/Oct/2019:15:06:10 -0300] "GET /products/1/presentation/new HTTP/1.1" 200 - 0.0014
В чем проблема?