Hemlock
Hemlock

Reputation: 6210

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.

Upvotes: 5

Views: 1827

Answers (2)

Hemlock
Hemlock

Reputation: 6210

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'
)

Upvotes: 4

three
three

Reputation: 8478

You can add the params to route like this "/bar?param=1&anotherparam=3"

Upvotes: 0

Related Questions