3 Comments

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.

3 Comments

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

Comments are closed.