Forum: Ruby on Rails Clearing out filters in ActionController

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-04-03 07: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'
    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
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-04-03 07:45
(Received via mailing list)
btw, the around_filter that I'm using is the ScopedAccess::Filter
described in http://habtm.com/articles/2006/02/22/nested-with_scope
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-04-03 17:25
(Received via mailing list)
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
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-04-03 23: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?

Pat
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-04-04 00:50
(Received via mailing list)
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
This topic is locked and can not be replied to.