如何为每个控制器栏设置一个before_filter?

问题描述:

在Ruby on Rails中,我想为每个控制器添加一个before_filter,除了一个。目前,我有在ApplicationController如何为每个控制器栏设置一个before_filter?

before_filter :authenticate 

是否有应用内ApplicationController这条规则,而不是在每个控制器加入before_filter :authenticate除了公众控制器的方法吗?

+0

的[跳过对Rails的before_filter(http://*.com/questions/2390178/skip-复制前过滤功能于导轨) – 2010-09-01 14:36:35

把前过滤器ApplicationController,然后跳到它的控制器,你不希望它:

skip_before_filter :authenticate 

如果你想运行在每个控制器一个,但这个过滤器,为什么不干脆跳过它?

class PublicController < ApplicationController 
    skip_before_filter :authenticate 
end 

如果你想跳过一个特定的动作,你可以使用:except

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