2009-12-24 50 views
1

我的应用程序控制器看起来像这样为什么before_filter没有像我期望的那样使用restful-authentication?

class ApplicationController < ActionController::Base 
    include AuthenticatedSystem 
    helper :all # include all helpers, all the time 
    protect_from_forgery # :secret => 'sup3rs3cr3t' 
    filter_parameter_logging :password 

    # Here's the interesting bit 
    before_filter :login_required, :except => [:index, :show, :new] 
end 

现在我还有一个控制器,它看起来像这样

class CompletelySecretController < ApplicationController 

    # the other interesting bit 
    before_filter :login_required 
    def index 
    @secrets = Secret.find(:all) 
    end 
end 

我仍然可以看到所有的秘密,尽管我指出一个需要登录的所有与

before_filter :login_required

行为难道不是直观认为子类中的将覆盖父类中的before_filter

回答

1

before_filter在你的子类中不覆盖超类中的同一个调用,但是它们相互堆栈。过滤器链是如何工作的。如果您想跳过ApplicationController中添加的过滤器,则可以使用skip_before_filter方法 - 请参阅“过滤器跳过链接”部分here in the filters documentation

相关问题