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.
Ba5816b2a9c23d87324e3b98beabba8c?d=identicon&s=25 alisonrowland (Guest)
on 2005-12-07 20: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
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 ksruby (Guest)
on 2005-12-07 20: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.