Run another route with query string inside Sinatra

I am writing a route that links the response of several routes, so I need to call other routes from Sinatra. I found this code in Sinatra README for this:

status, headers, body = call env.merge("PATH_INFO" => '/bar') 

However, it does not send a query string. So I tried this:

 status, headers, body = call env.merge( "PATH_INFO" => '/bar', "QUERY_STRING" => 'param=1' ) 

This does not work. How can I call another route and pass the query string so that the values ​​in the string end with the params hash of the route being called.

We use Sinatra 1.3.1 and Rack 1.3.5.

+4
source share
2 answers

So the solution is to clear the @original_params variable. It is clear that even if it appears in SINATRA README, this is not supported. If time permits, I would rework my routes, so this is not required, but you are there.

 @original_params = nil status, headers, body = call env.merge( "PATH_INFO" => '/bar', "QUERY_STRING" => 'param=1' ) 
+3
source

You can add parameters for the route as follows: "/bar?param=1&anotherparam=3"

0
source

Source: https://habr.com/ru/post/1394006/


All Articles