Before_filter :action_name OR :action_name

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?

On Mar 5, 11:26 pm, Shuaib85 [email protected] 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

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. [email protected]

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

2009/3/6 Frederick C. [email protected]

On Mar 5, 11:46 pm, Shuaib85 [email protected] 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