I want to run a single filter in my application.rb file, and then if a certain condition is true, end the action''s processing immediately. Right now I''m using prepend_before_filter to ensure that it gets run first, but some of my around_filters are still being processed. Is there a way that I can clear out all the filters that should be run? Basically it''ll look something like this: class ApplicationController < ActionController::Base prepend_before_filter :check_domain def check_domain unless valid_site? request.filters.clear # This isn''t the right code, I just don''t know what is render :text => ''This site has not been set up yet'' end end end valid_site?''s implementation doesn''t matter obviously... Also, if I use prepend_before_filter, will it actually run before the filters set up with around_filter? Perhaps I don''t quite understand how the filters work exactly. But basically before anything happens, I want to check for one condition, and then stop processing if that condition exists. Thanks, Pat
btw, the around_filter that I''m using is the ScopedAccess::Filter described in http://habtm.com/articles/2006/02/22/nested-with_scope On 4/2/06, Pat Maddox <pergesu@gmail.com> wrote:> I want to run a single filter in my application.rb file, and then if a > certain condition is true, end the action''s processing immediately. > Right now I''m using prepend_before_filter to ensure that it gets run > first, but some of my around_filters are still being processed. Is > there a way that I can clear out all the filters that should be run? > Basically it''ll look something like this: > > class ApplicationController < ActionController::Base > prepend_before_filter :check_domain > > def check_domain > unless valid_site? > request.filters.clear # This isn''t the right code, I just > don''t know what is > render :text => ''This site has not been set up yet'' > end > end > end > > valid_site?''s implementation doesn''t matter obviously... > > Also, if I use prepend_before_filter, will it actually run before the > filters set up with around_filter? Perhaps I don''t quite understand > how the filters work exactly. But basically before anything happens, > I want to check for one condition, and then stop processing if that > condition exists. > > Thanks, > Pat >
Ezra Zygmuntowicz
2006-Apr-03 15:24 UTC
[Rails] Re: Clearing out filters in ActionController
Pat- If you want to halt the filter chain you just need to return false in the filter. I am not certain if prepend_before_filter will make that filter the very first one or not but its worth a shot ;) Cheers- -Ezra On Apr 2, 2006, at 10:44 PM, Pat Maddox wrote:> btw, the around_filter that I''m using is the ScopedAccess::Filter > described in http://habtm.com/articles/2006/02/22/nested-with_scope > > > On 4/2/06, Pat Maddox <pergesu@gmail.com> wrote: >> I want to run a single filter in my application.rb file, and then >> if a >> certain condition is true, end the action''s processing immediately. >> Right now I''m using prepend_before_filter to ensure that it gets run >> first, but some of my around_filters are still being processed. Is >> there a way that I can clear out all the filters that should be run? >> Basically it''ll look something like this: >> >> class ApplicationController < ActionController::Base >> prepend_before_filter :check_domain >> >> def check_domain >> unless valid_site? >> request.filters.clear # This isn''t the right code, I just >> don''t know what is >> render :text => ''This site has not been set up yet'' >> end >> end >> end >> >> valid_site?''s implementation doesn''t matter obviously... >> >> Also, if I use prepend_before_filter, will it actually run before the >> filters set up with around_filter? Perhaps I don''t quite understand >> how the filters work exactly. But basically before anything happens, >> I want to check for one condition, and then stop processing if that >> condition exists. >> >> Thanks, >> Pat >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hey Ezra, I used prepend_before_filter to run a particular filter, and then return false in it, and everything works as I want it - no other filters were evaluated. Thanks for the tip. In a bunch of my filters, I''m making the exact same DB query. I''d like to cache this some how so that I don''t make the same query 3-5 times on every request. I can''t just stick it in a @variable though because then that belongs to the controller, which gets reused, right? So what would be the best way to do this - put it in flash? Pat On 4/3/06, Ezra Zygmuntowicz <ezmobius@gmail.com> wrote:> Pat- > > If you want to halt the filter chain you just need to return false > in the filter. I am not certain if prepend_before_filter will make > that filter the very first one or not but its worth a shot ;) > > Cheers- > -Ezra > > On Apr 2, 2006, at 10:44 PM, Pat Maddox wrote: > > > btw, the around_filter that I''m using is the ScopedAccess::Filter > > described in http://habtm.com/articles/2006/02/22/nested-with_scope > > > > > > On 4/2/06, Pat Maddox <pergesu@gmail.com> wrote: > >> I want to run a single filter in my application.rb file, and then > >> if a > >> certain condition is true, end the action''s processing immediately. > >> Right now I''m using prepend_before_filter to ensure that it gets run > >> first, but some of my around_filters are still being processed. Is > >> there a way that I can clear out all the filters that should be run? > >> Basically it''ll look something like this: > >> > >> class ApplicationController < ActionController::Base > >> prepend_before_filter :check_domain > >> > >> def check_domain > >> unless valid_site? > >> request.filters.clear # This isn''t the right code, I just > >> don''t know what is > >> render :text => ''This site has not been set up yet'' > >> end > >> end > >> end > >> > >> valid_site?''s implementation doesn''t matter obviously... > >> > >> Also, if I use prepend_before_filter, will it actually run before the > >> filters set up with around_filter? Perhaps I don''t quite understand > >> how the filters work exactly. But basically before anything happens, > >> I want to check for one condition, and then stop processing if that > >> condition exists. > >> > >> Thanks, > >> Pat > >> > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Ezra Zygmuntowicz
2006-Apr-03 22:48 UTC
[Rails] Re: Clearing out filters in ActionController
Pat- These are all filters in the controller? Then you should be able to use an @var if you want. Otherwise the flash might be a good place for it since it will get cleared automatically. -Ezra On Apr 3, 2006, at 2:19 PM, Pat Maddox wrote:> Hey Ezra, > > I used prepend_before_filter to run a particular filter, and then > return false in it, and everything works as I want it - no other > filters were evaluated. Thanks for the tip. > > In a bunch of my filters, I''m making the exact same DB query. I''d > like to cache this some how so that I don''t make the same query 3-5 > times on every request. I can''t just stick it in a @variable though > because then that belongs to the controller, which gets reused, right? > So what would be the best way to do this - put it in flash? > > Pat > > > On 4/3/06, Ezra Zygmuntowicz <ezmobius@gmail.com> wrote: >> Pat- >> >> If you want to halt the filter chain you just need to >> return false >> in the filter. I am not certain if prepend_before_filter will make >> that filter the very first one or not but its worth a shot ;) >> >> Cheers- >> -Ezra >> >> On Apr 2, 2006, at 10:44 PM, Pat Maddox wrote: >> >>> btw, the around_filter that I''m using is the ScopedAccess::Filter >>> described in http://habtm.com/articles/2006/02/22/nested-with_scope >>> >>> >>> On 4/2/06, Pat Maddox <pergesu@gmail.com> wrote: >>>> I want to run a single filter in my application.rb file, and then >>>> if a >>>> certain condition is true, end the action''s processing immediately. >>>> Right now I''m using prepend_before_filter to ensure that it gets >>>> run >>>> first, but some of my around_filters are still being processed. Is >>>> there a way that I can clear out all the filters that should be >>>> run? >>>> Basically it''ll look something like this: >>>> >>>> class ApplicationController < ActionController::Base >>>> prepend_before_filter :check_domain >>>> >>>> def check_domain >>>> unless valid_site? >>>> request.filters.clear # This isn''t the right code, I just >>>> don''t know what is >>>> render :text => ''This site has not been set up yet'' >>>> end >>>> end >>>> end >>>> >>>> valid_site?''s implementation doesn''t matter obviously... >>>> >>>> Also, if I use prepend_before_filter, will it actually run >>>> before the >>>> filters set up with around_filter? Perhaps I don''t quite >>>> understand >>>> how the filters work exactly. But basically before anything >>>> happens, >>>> I want to check for one condition, and then stop processing if that >>>> condition exists. >>>> >>>> Thanks, >>>> Pat >>>> >>> _______________________________________________ >>> Rails mailing list >>> Rails@lists.rubyonrails.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails