Send parameter along with method in before_filter


#1

Hello list,

I have an app that has a very simple authorization scheme. A person can
have
many roles and roles can have many people.

In my app, I’d like to do

before_filter :login_required (since no role name is provided, it
accepts
any users with credentials)
before_filter :login_required (“administrator”) (only accepts those with
role administrator)
before_filter :login_required {“administrator”, “buyer”, “seller”}
(accepts
those with roles admin, buyer, seller)

Now, I know the only way you can achieve this is to use the lambda
function,
but to me it looks very ugly. Right now I have multiple before_filter,
first
checking if they are logged in, then checking their role, etc.

Is there any other way around this that Im not seeing? I tried to come
up
with an answer using sessions, but it got far too complicated.

Any help would be fantastic,

Jin


#2

On Feb 27, 2006, at 2:18 PM, Jin L. wrote:

with role administrator)

Any help would be fantastic,

Jin


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

Jin-

I have a simple plugin that does thing for you with an easy

declarative syntax and then it defines all the before filters for
you. There is a write up here:

Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid


#3

Erza,

lovely! I was able to get your acl system running, and its working
smooth as
butter now. I wasn’t being DRY in my code and this really cleaned things
up.
Thank you very much,

Jin


#4

Lin-

Your welcome! I'm glad you could use it. Please do give feedback if

you run into any issues or you have an idea you wold like to see
added to the plugin.

-Ezra

On Feb 28, 2006, at 10:08 AM, Jin L. wrote:

with role administrator)
complicated.
Jin-
WebMaster


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid