All, I have my check_authentication and login stuff in my base ApplicationController in application.rb (I realize that these could/should be in another controller). What''s nice about this setup is that I can apply authorization checking to my entire app. just by providing a before_filter in ApplicationController. However, now I''m writing a controller whose methods allow users to request a login, which obviously should be not checking for authentication. But I can only "except" methods by name, not by controller membership. I got around this by overriding the check_authentication method (defined in ApplicationController) to do nothing in this particular controller. This works, but feels kludgy. Has any thought been given to allowing before_filter :only and :except arrays to accept controller names as well as individual actions. Then I could just "except" this controller from the before_filter and still get the benefit of defining the before_filter only once in ApplicationController. Thanks, Wes -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Wes Bangerter
2007-Feb-01 22:11 UTC
Re: Extending before_filter scope to entire controllers?
You can skip the before_filter by adding this to your controller: skip_before_filter :check_authentication :only and :except work too, so you can apply it to specific actions in that controller. See "Filter chain skipping" here http://api.rubyonrails.com/classes/ ActionController/Filters/ClassMethods.html On Feb 1, 3:49 pm, Wes Gamble <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> All, > > I have my check_authentication and login stuff in my base > ApplicationController in application.rb (I realize that these > could/should be in another controller). What''s nice about this setup is > that I can apply authorization checking to my entire app. just by > providing a before_filter in ApplicationController. > > However, now I''m writing a controller whose methods allow users to > request a login, which obviously should be not checking for > authentication. But I can only "except" methods by name, not by > controller membership. > > I got around this by overriding the check_authentication method (defined > in ApplicationController) to do nothing in this particular controller. > This works, but feels kludgy. > > Has any thought been given to allowing before_filter :only and :except > arrays to accept controller names as well as individual actions. Then I > could just "except" this controller from the before_filter and still get > the benefit of defining the before_filter only once in > ApplicationController. > > Thanks, > Wes > > -- > Posted viahttp://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-/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 -~----------~----~----~----~------~----~------~--~---
Wes Bangerter wrote:> You can skip the before_filter by adding this to your controller: > > skip_before_filter :check_authentication > > :only and :except work too, so you can apply it to specific actions in > that controller. > > See "Filter chain skipping" here http://api.rubyonrails.com/classes/ > ActionController/Filters/ClassMethods.html > > > On Feb 1, 3:49 pm, Wes Gamble <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Thx! Forgot about that one. -- 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-/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 -~----------~----~----~----~------~----~------~--~---