env["action_dispatch.parameter_filter"] = [:password]
# => replaces the value to all keys matching /password/i with "[FILTERED]"
filter
# 具体包含下面 3 项内容:
filtered_parameters
filtered_env
filtered_path
filtered_env
# => 一大串 env 相关数据
request.filtered_parameters
# => {"utf8"=>"✓",
"authenticity_token"=>"+.../hHj0C5Ao7CxXYwlejyghpNM3elUVw==",
"user"=>{"name"=>"kelby", "email"=>""},
"commit"=>"Create User",
"controller"=>"users",
"action"=>"create"}
request.filtered_path
# => "/users"
# 用 "[FILTERED]" 替换 /password/i
env["action_dispatch.parameter_filter"] = [:password]
# 用 "[FILTERED]" 替换 /foo|bar/i
env["action_dispatch.parameter_filter"] = [:foo, "bar"]
# filter_parameter_logging.rb
Rails.application.config.filter_parameters += [:password]
Rails.application.config.filter_parameters
env_filter
filtered_query_string
parameter_filter_for
parameter_filter
Note: 用得比较多的是方法 parameter_filter,通常用来配置过滤 :password ... 过滤的其实是 ParameterFilter 的实例对象,虽然这里没有体现出来。