Skip All Rails Filters
It took me a while to figure this out, but it’s quite simple. If you want to skip all of the filters a Rails controller will run, simply put the following at the top of your controller:
-
skip_filter filter_chain #both documented in the Rails API
For example, if your application controller defines a filter to check if a user is logged in, it makes sense that this filter might run for all controllers, except in rare cases. In my case, I have a dynamic image controller that doesn’t require all of the overhead that most controllers do. For that controller, I use the above to skip all of the filters.
November 12th, 2008 at 10:59 am
This is exactly what I was looking for. It looks like it runs on rails 2.1 just fine, but on 2.0 not so much
November 12th, 2008 at 11:48 am
after doing a little debugging I found that in rails 2.0 the objects in filter_chain are stored a lot differently.
See: http://pastie.org/private/rwrvphoz8yrntrgn21a
July 5th, 2009 at 6:43 am
I found exactly this code in an project I am trying to bring up to date for a client.
I found myself using the following instead
class ApplicationController
def self.skip_all_filters(options = {})
filter_chain.map(&:method).each do |filter|
skip_filter filter, options
end
end
end
class FooController [:blah, :blah2]
end