# Filter customization

**URL:** <https://www.ruby-forum.com/t/filter-customization/92029>\
**Category:** Rails\
**Created:** [April 14, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/filter-customization/92029 "2007-04-14T21:53:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cinek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@cinek](https://www.ruby-forum.com/u/cinek)\
**Post date:** [April 14, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/filter-customization/92029/1 "2007-04-14T21:53:22Z")

</div>

It’s more of a Ruby question than Rails specifically, but anyway…

I’m trying to make a generic filter that could be customized with  
options (it’s for authorization, but that doesn’t matter).

Currently I see two sensible approaches:

before\_filter { |controller| controller.authorize\_filter(OPTIONS) }

where authorize\_filter is a controller’s method and does the work  
depending on options, and:

before\_filter(&create\_authorizator(OPTIONS))

where create\_authorizator returns a Proc object.

I have implemented the second one since, depending on OPTIONS, the  
resulting filters may be quite different, so I’m returning different  
blocks of code.  
The problem is that Proc returned by create\_authorizator doesn’t have  
access to protected methods of controller (obvious).

The first solution seems less elegant to me, but since it can use  
protected methods I’ll have to switch to it.

## Do you know of any other/better ways of achieving something similar?

Marcin S.
