如何仅在Rails路由中获取查询字符串? [英] How do I get only the query string in a Rails route?
本文介绍了如何仅在Rails路由中获取查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这样的路线
match "/v1/:method" => "v1#index"
我的意图是捕获api方法的名称,然后发送请求到控制器内部的那个方法。
My intention here is capture the name of the api method and then send the request to that method inside the controller.
def index
self.send params[:method], params
end
我认为这会将其他参数作为该方法的参数发送,但没有用。因此,我的问题是如何在查询字符串中传递非方法参数?
I figured this would send the other parameters as an argument to the method, but it didn't work. So my question is how can I pass the non-method parameters in a query string?
推荐答案
#query_parameters
的作用恰恰是您想要:
#query_parameters
does exactly what you want:
request.query_parameters
这也是最有效的解决方案,因为它不像其他哈希表那样构造新的哈希。
It's also the most efficient solution since it doesn't construct a new hash, like the other ones do.
这篇关于如何仅在Rails路由中获取查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文