Read more

Rails: Configure ActionController to raise when strong params are invalid

Andreas Robecke
July 16, 2017Software engineer

Put the line below in the respective env.rb file to make your action controllers raise an ActionController::UnpermittedParameters error when strong params are not valid. This might come in handy when you are implementing an API and you want to let the user know that the request structure was invalid. You can then rescue those errors by implementing a rescue_from to have a generic handling of those cases. Note that you might need to whitelist common params such as :format to not raise on valid requests.

config.action_controller.action_on_unpermitted_parameters = :raise
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

Note: In case a required parameter params.require(:property).permit(...) was not provided or is nil, you will get a ActionController::ParameterMissing error. So you might want to rescue from both.

Posted by Andreas Robecke to makandra dev (2017-07-16 15:06)