jhund / filterrific

Filterrific is a Rails Engine plugin that makes it easy to filter, search, and sort your ActiveRecord lists.
http://filterrific.clearcove.ca
MIT License
910 stars 124 forks source link

NameError - undefined local variable or method `view_context` for controller inheriting from `ActionController::API` #209

Open ravibhusal opened 2 years ago

ravibhusal commented 2 years ago

Rails version: 6.0.3.6 Filterrific version: 5.2.1

As the title says, I am getting NameError - undefined local variable or method view_context when trying to use Filterrific in a controller inheriting from ActionController::API.

I have traced down the problem to https://github.com/jhund/filterrific/blob/312d071081a6c5ec80995c76cdb707e8097e2964/lib/filterrific/action_controller_extension.rb#L101-L103

where the helpers method calls view_context which is undefined because its not available for ActionController::API. I think it makes sense.

For now, I can set sanitize_param to false and sanitize the params myself. I just want to make sure its an actual issue and not just something occurring only on my end because of some misconfiguration.

Thank you for the help and the gem!