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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)