views:

33

answers:

2

In Ruby on Rails, I would like to add a before_filter to every controller except for one. Currently I have in ApplicationController:

before_filter :authenticate

Is there a way to apply this rule inside ApplicationController rather than adding before_filter :authenticate in every controller except the public controller?

+1  A: 

Put the before filter in ApplicationController and then skip it in the controller where you don't want it:

skip_before_filter :authenticate
marcgg
+3  A: 

If you want to run this filter in every controller but one, why not simply skip it?

class PublicController < ApplicationController
  skip_before_filter :authenticate
end

If you want to skip a particular action, you can use :except:

before_filter :authenticate, :except => [ :index ]
tadman