2009-12-24 48 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

相關問題