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:

  1. 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.

Tags: , ,

3 Responses to “Skip All Rails Filters”

  1. Ben Says:

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

  2. Ben Says:

    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

  3. RobL Says:

    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

Leave a Reply