ruby-on-railsruby-on-rails-3loggingactioncontroller

Rails 3.2.x: how to filter long parameters from getting logged using ActionController action?


There are similar questions like this, this, and this.

None help because the goal is to prevent logging of long parameters within a specific action instead of using config.filter_parameters. Also the answer must work for Rails 3.2.x while many answers are based on Rails 5.

One answer suggests calling request.filtered_parameters inside the controller method, but calling request.filtered_parameters.delete :long_param did not stop :long_param from getting logged.


Solution

  • config.filter_parameters takes a lambda function, so you can filter whatever you want. See answers here and here.

    If you only want to filter long arguments for a specific action, well, you are making your life unnecessarily complicated. Either filter all long parameters, using your lambda to set a limit on parameter value length, or change the parameter key of the action you want to filter so that it is unique and and then just filter by that key.