简体   繁体   English

Ruby on Rails:解码来自 url 的参数

[英]Ruby on Rails: decoding params from url

I begin to create a rails API for react.我开始为反应创建一个轨道 API。 I pass a GET request with params inside url like this:我在 url 中传递了一个带有参数的 GET 请求,如下所示:

api/dashboard/price?"foo"="bar"

But my rails app by default cannot decode it properly and on backend side.但是我的 Rails 应用程序默认无法在后端正确解码。 My params object looks this way:我的参数 object 看起来是这样的:

<ActionController::Parameters {"\"foo\""=>"\"bar\"", "controller"=>"api/dashboards", "action"=>"price"} permitted: false>

Furthermore I cannot access any of those keys eg:此外,我无法访问这些密钥中的任何一个,例如:

params[:foo]

returns nil返回零

How can I get rid of those slashes and decode url params proper way?我怎样才能摆脱那些斜线并以正确的方式解码 url 参数?

If you want to pass url params with quotes "foo" then you should also access them with quotes like this: params['"foo"'] .如果你想用引号"foo"传递 url 参数,那么你也应该用这样的引号访问它们: params['"foo"']

But if you want to make params[:foo] work then just pass them without any quotes.但是如果你想让params[:foo]工作,那么只需传递它们而不带任何引号。 api/dashboard/price?foo=bar . api/dashboard/price?foo=bar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM