开发者

How to set a before_filter for every controller bar one?

开发者 https://www.devze.com 2023-01-13 20:16 出处:网络
In Ruby on Rails, I would like to add a before_filter to every controller except for one.Currently I have in ApplicationController:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消