2017-05-23 52 views
3

首先,我知道wice_grid gem目前不支持rails 5。所以,网络上已经出现了问题。如何在使用wice_grid gem for rails时启用`raise_on_unfiltered_pa​​rameters`来尊重参数过滤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意外忽略参数过滤,并改为强制执行它在Rails 5.1中。

启用raise_on_unfiltered_parameters以尊重参数筛选,这是新应用程序中的默认设置。

对于现有的弃用行为,请改为调用#to_unsafe_h。

拒绝警告:num_pages已弃用,将在Kaminari 1.0中删除。请改用total_pages。

上面的代码根据需求生成数据网格,但无法显示过滤结果。

根据我的主要调试,我发现params有空值导致这个错误。

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

回答

2

按照警告,并添加

config.action_controller.raise_on_unfiltered_parameters = true

到config/application.rb中

在此之后.to_hash将转换只允许PARAMS。

相关问题