Custom filtering of parameters in rails 3 using config.filter_parameters

前端 未结 1 901
刺人心
刺人心 2021-01-03 01:54

I\'m working on upgrading from Rails 2.3.11 to 3.0.10, and am having trouble converting what is in the ApplicationController\'s filter_parameter_logging

相关标签:
1条回答
  • 2021-01-03 02:22

    Figured it out. You can pass a lambda statement to config.filter_parameters, so after I add the parameters to filter, I have this now:

    config.filter_parameters << lambda do |k,v|
      begin
        # Bail immediately if we can
        next unless v =~ FILTER_WORDS_REGEX && (v.index("=") || v.index("%3D"))
    
        #Filters out values for params that match
        v.gsub!(FILTER_WORDS_GSUB_REGEX) do
          "#{$1}=[FILTERED]#{$2}"
        end
      rescue Exception => e
        logger.error e
      end
    end
    
    0 讨论(0)
提交回复
热议问题