Rails-6 GET请求上的不允许的参数

问题描述 投票:0回答:1

我最近正在将Rails v5.2.3应用程序升级到Rails v6.0.2。在遵循Rails升级指南中描述的步骤之后,当我启动Rails服务器并执行GET请求时,我得到Unpermitted parameters: :page, :sort, :beds, :baths, :floors

  • Rails-6现在是否也对GET请求强制使用强参数?
  • 有没有一种方法可以通过一个来源来传递/允许我的应用程序中每个GET请求的所有参数(可能在config文件夹中定义一些配置设置,而不是在每个方法上都使用params.permit

这里是回溯:

Started GET "/search?page=1&sort=mp&beds%5B%5D=4&baths%5B%5D=4&floors%5B%5D=2"
Processing by BuildingsController#search as HTML
Parameters: {"page"=>"1", "sort"=>"mp", "beds"=>["4"], "baths"=>["4"], "floors"=>["2"]}
[Unpermitted parameters: :page, :sort, :beds, :baths, :floors

应用程序详细信息:

  • 红宝石2.6.5
  • rails 6.0.2
  • bootsnap 1.4.5

提前感谢!

strong-parameters ruby-on-rails-6
1个回答
0
投票

调查并花了一些时间后,我才知道

  • 不是特定于Rails-6的。
  • Rails-6中的GET请求将不会抛出不允许的参数错误。
  • 我在控制器redirect_to no_search_results_path(params.except(:action, :controller)) and return中使用了这条线,这导致错误。我现在正在使用redirect_to no_search_results_path(params.to_enum.to_h.except(:action, :controller)) and return,现在似乎一切正常。
© www.soinside.com 2019 - 2024. All rights reserved.