简体   繁体   中英

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.

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. filter_params has a helper function which builds a hash from several params[:keys] so that might be the reason.

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.

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

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.

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

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.

This worked for me

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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