Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger another route with a query string inside Sinatra

I am writing a route that bundles the response of several routes together so I need to trigger other routes from within Sinatra. I found this code in the Sinatra README to do that:

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

It doesn't, however, send the query string. So I tried this:

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

That doesn't seem to work. How can I call another route and pass the query string such that the values in the string end up in the params hash of the called route.

We are using Sinatra 1.3.1 and Rack 1.3.5.

like image 368
Hemlock Avatar asked Oct 08 '22 20:10

Hemlock


1 Answers

So the solution is to clear out the @original_params variable. Clearly, even if it appears in the Sinatra README this is not supported. Time permitting I'd rework my routes so this isn't required, but there you are.

@original_params = nil
status, headers, body = call env.merge(
    "PATH_INFO" => '/bar', 
    "QUERY_STRING" => 'param=1'
)
like image 69
Hemlock Avatar answered Oct 12 '22 10:10

Hemlock