Shuaib85
2008-Jul-21 09:30 UTC
before_filter :except => [:controller => :main_menu] ??? do we have such thing
Hi all I have added a before_filter method in my application. Mainly most of the controllers use that method except one controller. The whole controller does not use this method, so I want to exclude it from the list I tried before_filter :authenticate, :except => [:methods_here ] but how can we make an except for a controller Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Carolyn
2008-Jul-21 09:44 UTC
Re: before_filter :except => [:controller => :main_menu] ??? do we have such thing
You can add guards in the filter, based on the controller and/or action names. Example: #in application.rb before_filter :login_required, :except => [:welcome,:login] def login_required return if self.controller_name == ''test'' <<----- GUARD unless current_user redirect_to login_invite_url end end PS: Ref link: http://www.techlists.org/archives/programming/railslist/2006-05/msg03732.shtml On Jul 21, 2:30 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all > > I have added a before_filter method in my application. Mainly most of > the controllers use that method except one controller. The whole > controller does not use this method, so I want to exclude it from the > list > > I tried > before_filter :authenticate, :except => [:methods_here ] > > but how can we make an except for a controller > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Shuaib85
2008-Jul-21 10:01 UTC
Re: before_filter :except => [:controller => :main_menu] ??? do we have such thing
Hi Thanks for the fast answer in fact I find a way there is a method called skip_before_filter which you add it into the controller and it will do the job Thanks On Jul 21, 5:44 pm, Carolyn <kiran.sou...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can add guards in the filter, based on the controller and/or > action > names. > Example: > > #in application.rb > before_filter :login_required, :except => [:welcome,:login] > > def login_required > return if self.controller_name == ''test'' <<----- GUARD > > unless current_user > redirect_to login_invite_url > end > end > PS: > Ref link:http://www.techlists.org/archives/programming/railslist/2006-05/msg03... > > On Jul 21, 2:30 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi all > > > I have added a before_filter method in my application. Mainly most of > > the controllers use that method except one controller. The whole > > controller does not use this method, so I want to exclude it from the > > list > > > I tried > > before_filter :authenticate, :except => [:methods_here ] > > > but how can we make an except for a controller > > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
kiranH
2008-Jul-21 10:13 UTC
Re: before_filter :except => [:controller => :main_menu] ??? do we have such thing
Great ! On Jul 21, 3:01 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi > > Thanks for the fast answer > in fact I find a way > there is a method called > skip_before_filter > which you add it into the controller and it will do the job > > Thanks > > On Jul 21, 5:44 pm, Carolyn <kiran.sou...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > You can add guards in the filter, based on the controller and/or > > action > > names. > > Example: > > > #in application.rb > > before_filter :login_required, :except => [:welcome,:login] > > > def login_required > > return if self.controller_name == ''test'' <<----- GUARD > > > unless current_user > > redirect_to login_invite_url > > end > > end > > PS: > > Ref link:http://www.techlists.org/archives/programming/railslist/2006-05/msg03... > > > On Jul 21, 2:30 pm, Shuaib85 <shuaib.za...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi all > > > > I have added a before_filter method in my application. Mainly most of > > > the controllers use that method except one controller. The whole > > > controller does not use this method, so I want to exclude it from the > > > list > > > > I tried > > > before_filter :authenticate, :except => [:methods_here ] > > > > but how can we make an except for a controller > > > > Thanks > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Hamil
2010-Aug-19 00:11 UTC
Re: before_filter :except => [:controller => :main_menu] ??? do we have such thing
Yeah I''m using the skip_before_filter method too, but still, it seems it would be better if you could specify a controller/action like your original posts suggests before_filter :custom_filter, :except => {:controler=>:action} that way you can include the filter on everything by applying it to the ApplicationController, and only remove it from the few controllers/actions that don''t need it. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jim Croft
2010-Aug-19 06:16 UTC
Re: Re: before_filter :except => [:controller => :main_menu] ??? do we have such thing
On 19 Aug 2010, at 01:11, Mark Hamil wrote:> Yeah I''m using the skip_before_filter method too, > but still, it seems it would be better if you could specify a > controller/action like your original posts suggests > > before_filter :custom_filter, :except => {:controler=>:action}before_filter :filter_method, :only => :action or before_filter :filter_method, :except => :action See the ''Filter conditions'' section of http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html Hope that helps, Jim -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.