简体   繁体   English

传递给 _path 路由助手时出现在 params[:format] 中的参数

[英]params appearing in params[:format] when passing to _path route helper

I have a function which calls a _path helper function with several parameters: v2_specific_path(user, filter_params) This works great, and in the controller method that handles this path I see both user and filter_params and their values.我有一个函数,它调用带有几个参数的 _path 辅助函数: v2_specific_path(user, filter_params)这很好用,在处理此路径的控制器方法中,我看到了userfilter_params及其值。

In fact if I try to print out params they don't show up, but if I print out either one of them then they print out fine.事实上,如果我尝试打印出params它们不会显示出来,但是如果我打印出它们中的任何一个,那么它们会打印得很好。 filter_params has a helper function which builds a hash from several params[:keys] so that might be the reason. filter_params有一个辅助函数,它从几个params[:keys]构建一个散列,所以这可能是原因。

What I'm trying to do is add another set of parameters to the function call: v2_specific_path(user, new_params, filter_params) Since I'm trying to add some functionality which requires passing some information to the underlying controller that resolves this request.我想要做的是向函数调用添加另一组参数: v2_specific_path(user, new_params, filter_params)因为我试图添加一些需要将一些信息传递给解决此请求的底层控制器的功能。

The problem is that this doesn't work and seems to screw things over:问题是这不起作用,似乎把事情搞砸了:

  1. If I put them in the middle: v2_specific_path(user, new_params, filter_params) , then all the other params work great, but new_params actually appear inside params[:format] as: params[:format]="param1=4&param2=hi如果我把它们放在中间: v2_specific_path(user, new_params, filter_params) ,那么所有其他参数都很new_params ,但new_params实际上出现在params[:format]中: params[:format]="param1=4&param2=hi
  2. If I put them at the end: v2_specific_path(user, filter_params, new_params) then filter_params doesn't get parsed at all and appears in params[:format] but new_format does appear to be parsed and appear in params correctly如果我把它们放在最后: v2_specific_path(user, filter_params, new_params) 然后filter_params根本没有被解析并出现在params[:format]new_format似乎被解析并正确出现在params

I can't seem to figure out why this is happening.我似乎无法弄清楚为什么会这样。 I've made sure I have correct params.require/params.permit values in the controller.我已经确保控制器中有正确的params.require/params.permit值。

Any help is appreciated, if anyone has any other alternatives to passing values from application_helper to a controller (via _path, or some shared variable) that would also help immensely感谢任何帮助,如果有人有任何其他替代方法可以将值从application_helper传递到控制器(通过 _path 或某些共享变量),这也将非常有帮助

Thank you!谢谢!

For anyone seeking a solution to this:对于任何寻求解决方案的人:

I fixed this by doing two things: 1) created proper new routes which suited my implementation (I tried to do something a bit too clever and decided to just create new relevant routes instead of doing something too dynamic 2) I added the params I needed in to the routes: /something/:param1/whatever/:param2 etc.我通过做两件事来解决这个问题:1)创建适合我的实现的适当的路由(我试图做一些太聪明的事情,并决定只创建新的相关路由而不是做一些太动态的事情 2)我添加了我需要的参数进入路线: /something/:param1/whatever/:param2等。

This worked for me这对我有用

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

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