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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 5, 11:26 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> any idea?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 5, 11:26 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > > any idea?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 5, 11:46 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 conditionNo - 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> > thanks > > On Mar 6, 1:35 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Mar 5, 11:26 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > > > any idea?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You could just have one new filter that calls the other two as appropriate. 2009/3/6 Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > > > On Mar 5, 11:46 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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 > > 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 > > > > thanks > > > > On Mar 6, 1:35 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > > On Mar 5, 11:26 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > > > > > any idea? > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---