使用 Sinatra 内的查询字符串触发另一条路由
我正在编写一条将多个路由的响应捆绑在一起的路由,因此我需要从 Sinatra 内部触发其他路由。我在 Sinatra 自述文件中找到了执行此操作的代码:
status, headers, body = call env.merge("PATH_INFO" => '/bar')
但是,它不会发送查询字符串。所以我尝试了这个:
status, headers, body = call env.merge(
"PATH_INFO" => '/bar',
"QUERY_STRING" => 'param=1'
)
这似乎不起作用。如何调用另一个路由并传递查询字符串,以便字符串中的值最终出现在被调用路由的参数哈希中。
我们使用的是 Sinatra 1.3.1 和 Rack 1.3.5。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此解决方案是清除
@original_params
变量。显然,即使它出现在 Sinatra README 中,这也是不受支持的。如果时间允许,我会重新设计我的路线,所以这不是必需的,但你已经完成了。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.您可以将参数添加到路由,如下所示
"/bar?param=1&anotherparam=3"
You can add the params to route like this
"/bar?param=1&anotherparam=3"