Forum: Ruby on Rails Filter customization

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
40caa7d562f4c348efe949638918d367?d=identicon&s=25 Marcin Simonides (cinek)
on 2007-04-14 21:53
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:


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 Simonides
This topic is locked and can not be replied to.