Forum: Ruby on Rails Send parameter along with method in before_filter

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.
Jin L. (Guest)
on 2006-02-28 00:20
(Received via mailing list)
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
Ezra Z. (Guest)
on 2006-02-28 00:39
(Received via mailing list)
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:

http://brainspl.at/articles/2006/02/20/new-plugin-acl_system

Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid
Jin L. (Guest)
on 2006-02-28 20:10
(Received via mailing list)
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
Ezra Z. (Guest)
on 2006-02-28 20:56
(Received via mailing list)
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
This topic is locked and can not be replied to.