Search code examples
ruby-on-railsexceptionactioncontroller

How to raise ActionController::UnpermittedParameters


I am whitelisting some parameters like

params.permit(:a, :b)

If someone sends some other query parameters in request, i am getting "UnpermitterParameters" exception as i have add this to my app config

config.action_controller.action_on_unpermitted_parameters = :raise

But while processing the query parameters if i get some invalid value for a key i want to raise the same exception.

When i do

raise ActionController::UnpermittedParameters "found unexpected parameter: c"

I get

NoMethodError: undefined method `UnpermittedParameters' for ActionController:Module

Can we raise the same exception ourselves ?


Solution

  • I think i have found the answer.

    We should used like below:

    raise ActionController::UnpermittedParameters.new [:c]