[英]How to set a before_filter for every controller bar one?
In Ruby on Rails, I would like to add a before_filter to every controller except for one. 在Ruby on Rails中,我想向除控制器之外的每个控制器添加一个before_filter。 Currently I have in
ApplicationController
: 目前我在
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? 有没有一种方法可以在
ApplicationController
应用此规则,而不是在除公共控制器之外的每个控制器中添加before_filter :authenticate
?
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
: 如果要跳过特定操作,可以使用
:except
:
before_filter :authenticate, :except => [ :index ]
将before过滤器放在ApplicationController
,然后在不需要的控制器中将其跳过:
skip_before_filter :authenticate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.