【问题标题】:Why doesn't before_filter work the way I expect with restful-authentication?为什么 before_filter 不能像我期望的那样使用 restful-authentication?
【发布时间】:2009-12-24 10:36:43
【问题描述】:

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

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覆盖父类中的before_filter是不是很直观?

【问题讨论】:

    标签: ruby-on-rails ruby inheritance oop


    【解决方案1】:

    您的子类中的before_filter 不会覆盖超类中的相同调用,而是它们彼此堆叠。这就是过滤器链的工作方式。如果你想跳过你的 ApplicationController 中添加的过滤器,你可以使用skip_before_filter 方法 - 参见“过滤器链跳过”部分here in the filters documentation

    【讨论】:

      猜你喜欢
      • 2010-10-13
      • 2021-11-19
      • 2012-02-16
      • 1970-01-01
      • 2022-11-12
      • 1970-01-01
      • 2010-10-04
      • 2019-06-28
      • 1970-01-01
      相关资源
      最近更新 更多