Clearing out filters in ActionController

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

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 :wink:

Cheers-
-Ezra

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

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