如何在对 rails 使用 wice_grid gem 时启用 `raise_on_unfiltered_parameters` 以遵守参数过滤 5

How to Enable `raise_on_unfiltered_parameters` to respect parameter filtering while using wice_grid gem for rails 5

首先,我知道 wice_grid gem 目前不支持 rails 5。因此,网络上已经存在一些问题。

但现在我无法返回,因为我正在开发 Web 应用程序。

问题:

我想要一个在我的应用程序中具有过滤器属性的简单数据网格。下面是我的代码:

customers_controller.rb

class CustomersController < ApplicationController
  layout "themeLayout"
  before_action :permit_params

  def index
    @grid = initialize_grid(Customer)
  end

  def permit_params
    params.permit!
  end
end

index.html.erb

   <%= grid(@grid) do |g|

    g.column name: 'Id' do |task|
      task.id
    end

    g.column name: 'Name', attribute: 'name'  do |task|
      task.name
    end

    g.column name: 'Company Name', attribute: 'company_name' do |task|
      task.company_name
    end

end %>

日志文件

to_hash unexpectedly ignores parameter filtering, and will change to enforce it in Rails 5.1.

Enable raise_on_unfiltered_parameters to respect parameter filtering, which is the default in new applications.

For the existing deprecated behaviour, call #to_unsafe_h instead.

DEPRECATION WARNING: num_pages is deprecated and will be removed in Kaminari 1.0. Please use total_pages instead.

以上代码根据要求生成数据网格,但无法显示筛选结果。

根据我的初步调试,我发现 params 具有空值,导致此错误。

任何指点将不胜感激...

按照警告添加

config.action_controller.raise_on_unfiltered_parameters = true

到config/application.rb

在此之后。to_hash 将仅转换允许的参数。