Forum: Ruby on Rails Clearing out filters in ActionController

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Pat M. (Guest)
on 2006-04-03 09:15
(Received via mailing list)
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'

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.

Pat M. (Guest)
on 2006-04-03 09:45
(Received via mailing list)
btw, the around_filter that I'm using is the ScopedAccess::Filter
described in
Ezra Z. (Guest)
on 2006-04-03 19:25
(Received via mailing list)

	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 ;)

Pat M. (Guest)
on 2006-04-04 01:21
(Received via mailing list)
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?

Ezra Z. (Guest)
on 2006-04-04 02:50
(Received via mailing list)

	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.

This topic is locked and can not be replied to.