# Before\_Filter question

**URL:** <https://www.ruby-forum.com/t/before-filter-question/175550>\
**Category:** Rails\
**Created:** [September 15, 2009, 2:18pm UTC](https://www.ruby-forum.com/t/before-filter-question/175550 "2009-09-15T14:18:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [September 15, 2009, 2:18pm UTC](https://www.ruby-forum.com/t/before-filter-question/175550/1 "2009-09-15T14:18:29Z")

</div>

Guyz,

I am having a question for you…  
Scenario is i am using before\_filter in controller ABC to check that  
wheather user is administrator or not … and if not then it can show  
user only one page to user … did it like this…  
before\_filter :authorize\_admin, :except =\> :def

Now i want a condition that if the user is not admin but if he is a  
tailor then he can see two pages as well def and xyz …

Hope you people got it right… How can i came out from this dillema …  
🙂

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [September 15, 2009, 2:37pm UTC](https://www.ruby-forum.com/t/before-filter-question/175550/2 "2009-09-15T14:37:50Z")

</div>

Thats correct that :except can be an array of values but if gave them  
user can also see access the pages … even if he is neither a admin nor  
tailor …  
you mean to say that i have to do in this way …  
before\_filter :authorize\_admin, :except =\> [:def, :xyz]

Frederick C. wrote:

> On Sep 15, 1:18ï¿½pm, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > 
> 
> The value of :except can be an array of values. Or you may be in a  
> case where you just need to add that logic to authorize\_admin.
> 
> Fred

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [September 15, 2009, 2:29pm UTC](https://www.ruby-forum.com/t/before-filter-question/175550/3 "2009-09-15T14:29:56Z")

</div>

On Sep 15, 1:18 pm, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 

The value of :except can be an array of values. Or you may be in a  
case where you just need to add that logic to authorize\_admin.

Fred

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [September 15, 2009, 2:55pm UTC](https://www.ruby-forum.com/t/before-filter-question/175550/4 "2009-09-15T14:55:17Z")

</div>

Hemant B. wrote:

> Thats correct that :except can be an array of values but if gave them  
> user can also see access the pages … even if he is neither a admin nor  
> tailor …  
> you mean to say that i have to do in this way …  
> before\_filter :authorize\_admin, :except =\> [:def, :xyz]

Take a look at role\_requirement. It should give you some ideas on how to  
implement what you want, or you might be able to just use it as is:

> **[GitHub - timcharper/role\_requirement: Simple role based security for...](https://github.com/timcharper/role_requirement)**
>
> Simple role based security for restful\_authentication
> 
> I am no longer involved in this project. If you are interested in becoming the new maintainer and making it your own, please contact me. I wil...

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [September 15, 2009, 3:44pm UTC](https://www.ruby-forum.com/t/before-filter-question/175550/5 "2009-09-15T15:44:16Z")

</div>

before\_filter :authorize\_admin, :except =\> [:def, :xyz]  
before\_filter :authorize\_tailer, :only =\> [:def, :xyz] # if you have a  
method authorize\_tailer

## Thanks, Abhinav

à¤…à¤­à¤¿à¤¨à¤µ  
[http://twitter.com/abhinav](http://twitter.com/abhinav)

On Tue, Sep 15, 2009 at 6:07 PM, Hemant B. \<

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [September 15, 2009, 5:16pm UTC](https://www.ruby-forum.com/t/before-filter-question/175550/6 "2009-09-15T17:16:10Z")

</div>

On Sep 15, 3:37Â pm, Hemant B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Not working … In this case … authorize\_admin starts works …  
> Listen my case is if user is admin then show him all pages like :abc and  
> :def and :xyz and if user is a simple user then show him only :abc and  
> if user is an tailor then show him two pages :abc and :def …  
> All pages can be accessed by admin only …

Sounds like you might need to make your authorize filter a little  
smarter. The plugin Robert pointed out may do all you need or might  
provide suitable inspiration.

Fred

---

<div class="post-metadata">

**Author:** ![hemantborole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@hemantborole](https://www.ruby-forum.com/u/hemantborole)\
**Post date:** [September 15, 2009, 4:37pm UTC](https://www.ruby-forum.com/t/before-filter-question/175550/7 "2009-09-15T16:37:06Z")

</div>

Not working … In this case … authorize\_admin starts works …  
Listen my case is if user is admin then show him all pages like :abc and  
:def and :xyz and if user is a simple user then show him only :abc and  
if user is an tailor then show him two pages :abc and :def …  
All pages can be accessed by admin only …  
Hope u people now got it right…

Abhinav S. wrote:

> before\_filter :authorize\_admin, :except =\> [:def, :xyz]  
> before\_filter :authorize\_tailer, :only =\> [:def, :xyz] # if you have a  
> method authorize\_tailer
> 
> ## Thanks, Abhinav
> 
> à¤…à¤­à¤¿à¤¨à¤µ  
> [http://twitter.com/abhinav](http://twitter.com/abhinav)
> 
> On Tue, Sep 15, 2009 at 6:07 PM, Hemant B. \<
