# Before\_filter :action\_name OR :action\_name

**URL:** <https://www.ruby-forum.com/t/before-filter-action-name-or-action-name/162127>\
**Category:** Rails\
**Created:** [March 6, 2009, 12:27am UTC](https://www.ruby-forum.com/t/before-filter-action-name-or-action-name/162127 "2009-03-06T00:27:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [March 6, 2009, 12:27am UTC](https://www.ruby-forum.com/t/before-filter-action-name-or-action-name/162127/1 "2009-03-06T00:27:14Z")

</div>

Hi there

I am wondering if we can use before\_filter in the form of :action  
OR :action

what i want to do is to implement one of the actions, if the first  
failed, then go to the second

when i use  
before\_filter :action1  
before\_filter :action2

each method will run them, my case is that i want to check if one of  
them is true and not both

any idea?

---

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [March 6, 2009, 12:36am UTC](https://www.ruby-forum.com/t/before-filter-action-name-or-action-name/162127/2 "2009-03-06T00:36:02Z")

</div>

On Mar 5, 11:26 pm, Shuaib85 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> what i want to do is to implement one of the actions, if the first  
> failed, then go to the second
> 
> when i use  
> before\_filter :action1  
> before\_filter :action2
> 
> each method will run them, my case is that i want to check if one of  
> them is true and not both

sounds like you just want one filter that checks these 2 things.

Fred

---

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [March 6, 2009, 12:47am UTC](https://www.ruby-forum.com/t/before-filter-action-name-or-action-name/162127/3 "2009-03-06T00:47:45Z")

</div>

basically, I made my own user access level. In one case, the admin and  
the client can delete their posts. so I do not want to rewrite the  
methods in different name  
in my code i have something like this

before\_filter :login\_required, :only =\> [:delete, :edit, …]  
before\_filter :admin\_required, :only =\> [:delete, :edit, …]

some other methods can only be implemented by admin

so when I am logged in as client I cannot edit the post because i need  
to be admin as well, so is there a way to stop the before filter if  
one of them satisfied the condition

thanks

On Mar 6, 1:35 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [March 6, 2009, 9:46am UTC](https://www.ruby-forum.com/t/before-filter-action-name-or-action-name/162127/4 "2009-03-06T09:46:59Z")

</div>

You could just have one new filter that calls the other two as  
appropriate.

2009/3/6 Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [March 6, 2009, 1:52am UTC](https://www.ruby-forum.com/t/before-filter-action-name-or-action-name/162127/5 "2009-03-06T01:52:10Z")

</div>

On Mar 5, 11:46 pm, Shuaib85 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> so when I am logged in as client I cannot edit the post because i need  
> to be admin as well, so is there a way to stop the before filter if  
> one of them satisfied the condition

No - the only way the filter chain stops is if you redirect or render  
(and then the action is not executed). The obvious solution would be  
to make login\_required pass if the user is an admin, then in the  
example you gave you would only need

before\_filter :login\_required, :only =\> [:delete, :edit, …]

Fred
