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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)