Forum: Ruby on Rails Passing a parameter to a before_filter method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
alisonrowland (Guest)
on 2005-12-07 21:19
(Received via mailing list)
I've got a couple of before_filter methods which are partially
redundant. I'd like to merge them into one and just look at a passed
parameter to tell which path to take. So instead of doing this...

before_filter :authorize
OR
before_filter :authorize_admin

I'd like to be able to do...

before_filter :authorize
OR
before_filter :authorize("admin")

So far, I haven't been successful in doing this. Is this possible? Any
tips?

Thanks,
Alison
ksruby (Guest)
on 2005-12-07 21:23
(Received via mailing list)
Try

before_filter :authorize
before_filter lambda{ authorize("admin") }

But the second one might have some performance issues.

Kent.
This topic is locked and can not be replied to.