# Send parameter along with method in before\_filter

**URL:** <https://www.ruby-forum.com/t/send-parameter-along-with-method-in-before-filter/74406>\
**Category:** Rails\
**Created:** [February 27, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/send-parameter-along-with-method-in-before-filter/74406 "2006-02-27T23:20:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![typej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@typej](https://www.ruby-forum.com/u/typej)\
**Post date:** [February 27, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/send-parameter-along-with-method-in-before-filter/74406/1 "2006-02-27T23:20:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![typej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@typej](https://www.ruby-forum.com/u/typej)\
**Post date:** [February 27, 2006, 11:39pm UTC](https://www.ruby-forum.com/t/send-parameter-along-with-method-in-before-filter/74406/2 "2006-02-27T23:39:31Z")

</div>

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](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](http://brainspl.at/articles/2006/02/20/new-plugin-acl_system)

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![typej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@typej](https://www.ruby-forum.com/u/typej)\
**Post date:** [February 28, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/send-parameter-along-with-method-in-before-filter/74406/3 "2006-02-28T19:10:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![typej](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@typej](https://www.ruby-forum.com/u/typej)\
**Post date:** [February 28, 2006, 7:56pm UTC](https://www.ruby-forum.com/t/send-parameter-along-with-method-in-before-filter/74406/4 "2006-02-28T19:56:07Z")

</div>

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](http://lists.rubyonrails.org/mailman/listinfo/rails)

-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid
