Skip all filters
I found some code recently for a client that skips (or should at least) skip all filters in a controller. I haven’t seen this done before and a quick google clarified someone else has put it to use somewhere, as I wasn’t sure if this should ever have worked.
class FooController < ApplicationController
skip_filter filter_chain
end
http://markmcb.com/2008/10/14/skip-all-rails-filters/
It was actually implemented with a little more functionality to set options for all the filters that are being skipped. e.g only for particular actions in a controller.
class ApplicationController
def self.skip_all_filters(options = {})
skip_filter filter_chain, options
end
end
However, this doesn’t appear to work in post Rails 2.1 applications. So 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 < ApplicationController
before_filter :do_something
skip_all_filters :only => [:blah, :blah2]
end