代码之家  ›  专栏  ›  技术社区  ›  Blaine Lafreniere

为什么before_filter不能像我期望的那样使用restful身份验证?

  •  1
  • Blaine Lafreniere  · 技术社区  · 15 年前

    我的应用程序控制器如下所示

    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 回复  |  直到 15 年前
        1
  •  1
  •   morhekil    15 年前

    before_filter 在您的子类中,不会重写超级类中的同一调用,但它们会相互堆叠。这就是过滤器链的工作原理。如果要跳过应用程序控制器中添加的筛选器,可以使用 skip_before_filter 方法-请参阅“筛选链跳过”部分 here in the filters documentation .

    推荐文章