# Filter\_parameter\_logging

**URL:** <https://www.ruby-forum.com/t/filter-parameter-logging/114191>\
**Category:** Rails\
**Created:** [September 9, 2007, 2:16pm UTC](https://www.ruby-forum.com/t/filter-parameter-logging/114191 "2007-09-09T14:16:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ritesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@ritesh](https://www.ruby-forum.com/u/ritesh)\
**Post date:** [September 9, 2007, 2:16pm UTC](https://www.ruby-forum.com/t/filter-parameter-logging/114191/1 "2007-09-09T14:16:05Z")

</div>

Hi,

Is there a way to specify keys of a hash in params to  
filter\_parameter\_logging.

For example, my payment form sends creditcard[:number] and  
creditcard[:type] in params and I filter these keys using  
filter\_parameter\_logging :number, :type.

I don’t want :number and :type in other forms to be filtered. Is there  
a way to solve this?

thanks,  
Ritesh

---

<div class="post-metadata">

**Author:** ![ritesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@ritesh](https://www.ruby-forum.com/u/ritesh)\
**Post date:** [September 10, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/filter-parameter-logging/114191/2 "2007-09-10T18:33:37Z")

</div>

ritesh wrote:

> Hi,
> 
> Is there a way to specify keys of a hash in params to  
> filter\_parameter\_logging.
> 
> For example, my payment form sends creditcard[:number] and  
> creditcard[:type] in params and I filter these keys using  
> filter\_parameter\_logging :number, :type.
> 
> I don’t want :number and :type in other forms to be filtered. Is there  
> a way to solve this?
> 
> thanks,  
> Ritesh

This condition is more advanced that filter\_parameter\_logging is  
designed to handle. You’ll need to define your own filter\_parameters  
method for the controller. Here’s an example that may work for you:

def filter\_parameters(unfiltered)  
return unfiltered unless params[:action] == ‘payment’  
filtered = unfiltered.dup  
filtered[:creditcard] = unfiltered[:creditcard].dup  
filtered[:creditcard][:number] = ‘[FILTERED]’  
filtered[:creditcard][:type] = ‘[FILTERED]’  
filtered  
end

Jeremy
