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 :authent开发者_高级运维icate
in every controller except the public controller?
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 ]
Put the before filter in ApplicationController
and then skip it in the controller where you don't want it:
skip_before_filter :authenticate
精彩评论