How to filter parameters in rails?

前端 未结 5 711
南笙
南笙 2020-12-13 12:03

Rails has built in log filtering so you don\'t log passwords and credit cards. Works great for that but when you want to trigger a custom log (like to email) and send your

5条回答
  •  遥遥无期
    2020-12-13 12:56

    tadman answered correctly but here is some additional info:

    In application.rb

    config.filter_parameters += [:password, :password_confirmation, :credit_card]
    

    Wherever you are doing custom logging:

    f = ActionDispatch::Http::ParameterFilter.new(Rails.application.config.filter_parameters)
    f.filter :order => {:credit_card => "4111111111111111"}
    
     => {:order=>{:credit_card=>"[FILTERED]"}} 
    

提交回复
热议问题