Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

First, I do know that wice_grid gem is not supporting rails 5 as of now. So, there are issues already flowing around the web.

But now I can't go back as I am in the middle of my web app development.

Issue:

I want a simple datagrid having filter properties in my application. Below is my code:

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

log file

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.

Above code generates the data grid as per the requirement but it is not able to display the filtered results.

As per my primary debugging, I found out that params is having null value which results in this error.

Any pointers will be appreciated...

like image 996
Priyesh Doshi Avatar asked May 23 '17 18:05

Priyesh Doshi


1 Answers

Follow the warning and add

config.action_controller.raise_on_unfiltered_parameters = true

to config/application.rb

After this .to_hash will convert only permitted params.

like image 179
Alex Baidan Avatar answered Sep 24 '22 22:09

Alex Baidan