Hi. Is there any ability to except some controllers from "before_filter" action when it announced in application.rb? In case that i dont want to do some before_filter method on Image controller, for example. Sorry for too bad eng :( -- WIth best regards Ilya V. Sabanin
On 5/21/05, Ilya V. Sabanin <ilya.sabanin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi. > Is there any ability to except some controllers from "before_filter" > action when it announced in application.rb? In case that i dont want to > do some before_filter method on Image controller, for example.before_filter :login_required, :except => :show or before_filter :login_required, :on => [:new, :delete] There''s more of that Rails goodness in the Rails Docs: http://rails.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html -- rick http://techno-weenie.net
On 5/21/05, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5/21/05, Ilya V. Sabanin <ilya.sabanin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi. > > Is there any ability to except some controllers from "before_filter" > > action when it announced in application.rb? In case that i dont want to > > do some before_filter method on Image controller, for example.Scratch that... I didn''t read your msg carefully enough :) Multiple calls to before_filter append it to the stack. You might just have to add it to all the controllers that need it. -- rick http://techno-weenie.net
I wonder if it would be a good idea to have a remove_filter class method for subclasses?> Scratch that... I didn''t read your msg carefully enough :) > Multiple calls to before_filter append it to the stack. You might > just have to add it to all the controllers that need it. > > -- > rick > http://techno-weenie.net
How I insert more than one function?? like: before_filter :login_required, :admin_required, :on => :admin I created "admin_required" method Thank you, Pedro Rick Olson escreveu:>On 5/21/05, Ilya V. Sabanin <ilya.sabanin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>Hi. >>Is there any ability to except some controllers from "before_filter" >>action when it announced in application.rb? In case that i dont want to >>do some before_filter method on Image controller, for example. >> >> > >before_filter :login_required, :except => :show > >or > >before_filter :login_required, :on => [:new, :delete] > >There''s more of that Rails goodness in the Rails Docs: >http://rails.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html > > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
Call before_filter multiple times: before_filter :login_required before_filter :admin_required, :on => :admin before_filter is an alias for append_before_filter, so you''ll probly want to make sure you order filters correctly (the above ordering means that for each action :login_required is called, and then, for :admin only, :admin_required is called) or use prepend_before_filter instead. For more, read the docs, paying particular attention to the ''Filter chain ordering'' section: http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html On 5/23/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> > How I insert more than one function?? > like: > before_filter :login_required, :admin_required, :on => :admin > I created "admin_required" method > > Thank you, > Pedro > > > Rick Olson escreveu: > > >On 5/21/05, Ilya V. Sabanin <ilya.sabanin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > >>Hi. > >>Is there any ability to except some controllers from "before_filter" > >>action when it announced in application.rb? In case that i dont want to > >>do some before_filter method on Image controller, for example. > >> > >> > > > >before_filter :login_required, :except => :show > > > >or > > > >before_filter :login_required, :on => [:new, :delete] > > > >There''s more of that Rails goodness in the Rails Docs: > >http://rails.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html > > > > > > > > -- > > Pedro C. Valentini > pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > +55 (21) 8708-8035 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Please, How I do the same with layouts?? Can I set one layout for each action?? Because I have a admin area, like: User_Controller: layout ''admin'', :on => [:new, :delete, :edit] layout ''main'', :on => [:index, :login, :logout] The better way in put admin funcions for user in Admin_Controller or in User_Controller ?? Thank you, Pedro Chris Boone escreveu:>Call before_filter multiple times: > >before_filter :login_required >before_filter :admin_required, :on => :admin > >before_filter is an alias for append_before_filter, so you''ll probly >want to make sure you order filters correctly (the above ordering >means that for each action :login_required is called, and then, for >:admin only, :admin_required is called) or use prepend_before_filter >instead. > >For more, read the docs, paying particular attention to the ''Filter >chain ordering'' section: > >http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html > >On 5/23/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > >>How I insert more than one function?? >>like: >>before_filter :login_required, :admin_required, :on => :admin >>I created "admin_required" method >> >>Thank you, >>Pedro >> >> >>Rick Olson escreveu: >> >> >> >>>On 5/21/05, Ilya V. Sabanin <ilya.sabanin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> >>> >>> >>>>Hi. >>>>Is there any ability to except some controllers from "before_filter" >>>>action when it announced in application.rb? In case that i dont want to >>>>do some before_filter method on Image controller, for example. >>>> >>>> >>>> >>>> >>>before_filter :login_required, :except => :show >>> >>>or >>> >>>before_filter :login_required, :on => [:new, :delete] >>> >>>There''s more of that Rails goodness in the Rails Docs: >>>http://rails.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html >>> >>> >>> >>> >>> >>-- >> >>Pedro C. Valentini >>pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >>+55 (21) 8708-8035 >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
On 5/24/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> Please, > How I do the same with layouts?? > Can I set one layout for each action?? > Because I have a admin area, like: > User_Controller: > layout ''admin'', :on => [:new, :delete, :edit] > layout ''main'', :on => [:index, :login, :logout]you could just use the method form of layout class WeblogController < ActionController::Base layout :detect_correct_layout def index # fetching posts end private def detect_correct_layout if @request.something return ''admin; else return ''main'' end end ...> The better way in put admin funcions for user in Admin_Controller or in > User_Controller ?? > > Thank you, > Pedro > > Chris Boone escreveu: > > >Call before_filter multiple times: > > > >before_filter :login_required > >before_filter :admin_required, :on => :admin > > > >before_filter is an alias for append_before_filter, so you''ll probly > >want to make sure you order filters correctly (the above ordering > >means that for each action :login_required is called, and then, for > >:admin only, :admin_required is called) or use prepend_before_filter > >instead. > > > >For more, read the docs, paying particular attention to the ''Filter > >chain ordering'' section: > > > >http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html > > > >On 5/23/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > > > > >>How I insert more than one function?? > >>like: > >>before_filter :login_required, :admin_required, :on => :admin > >>I created "admin_required" method > >> > >>Thank you, > >>Pedro > >> > >> > >>Rick Olson escreveu: > >> > >> > >> > >>>On 5/21/05, Ilya V. Sabanin <ilya.sabanin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>> > >>> > >>> > >>> > >>>>Hi. > >>>>Is there any ability to except some controllers from "before_filter" > >>>>action when it announced in application.rb? In case that i dont want to > >>>>do some before_filter method on Image controller, for example. > >>>> > >>>> > >>>> > >>>> > >>>before_filter :login_required, :except => :show > >>> > >>>or > >>> > >>>before_filter :login_required, :on => [:new, :delete] > >>> > >>>There''s more of that Rails goodness in the Rails Docs: > >>>http://rails.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html > >>> > >>> > >>> > >>> > >>> > >>-- > >> > >>Pedro C. Valentini > >>pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > >>+55 (21) 8708-8035 > >> > >>_______________________________________________ > >>Rails mailing list > >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >>http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > >_______________________________________________ > >Rails mailing list > >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > -- > > Pedro C. Valentini > pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > +55 (21) 8708-8035 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
Try to separate your admin interface from users and you dont need such anfractuous layout declarations. Subfolders is good enough for separating controllers. Pedro Valentini wrote:> Please, > How I do the same with layouts?? > Can I set one layout for each action?? > Because I have a admin area, like: > User_Controller: > layout ''admin'', :on => [:new, :delete, :edit] > layout ''main'', :on => [:index, :login, :logout] > The better way in put admin funcions for user in Admin_Controller or > in User_Controller ?? > > Thank you, > Pedro > > Chris Boone escreveu: > >> Call before_filter multiple times: >> >> before_filter :login_required >> before_filter :admin_required, :on => :admin >> >> before_filter is an alias for append_before_filter, so you''ll probly >> want to make sure you order filters correctly (the above ordering >> means that for each action :login_required is called, and then, for >> :admin only, :admin_required is called) or use prepend_before_filter >> instead. >> >> For more, read the docs, paying particular attention to the ''Filter >> chain ordering'' section: >> >> http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html >> >> >> On 5/23/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: >> >> >>> How I insert more than one function?? >>> like: >>> before_filter :login_required, :admin_required, :on => :admin >>> I created "admin_required" method >>> >>> Thank you, >>> Pedro >>> >>> >>> Rick Olson escreveu: >>> >>> >>> >>>> On 5/21/05, Ilya V. Sabanin <ilya.sabanin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>> >>>> >>>> >>>>> Hi. >>>>> Is there any ability to except some controllers from "before_filter" >>>>> action when it announced in application.rb? In case that i dont >>>>> want to >>>>> do some before_filter method on Image controller, for example. >>>>> >>>>> >>>>> >>>> >>>> before_filter :login_required, :except => :show >>>> >>>> or >>>> >>>> before_filter :login_required, :on => [:new, :delete] >>>> >>>> There''s more of that Rails goodness in the Rails Docs: >>>> http://rails.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html >>>> >>>> >>>> >>>> >>>> >>> >>> -- >>> >>> Pedro C. Valentini >>> pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >>> +55 (21) 8708-8035 >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >> >