rails 3在过滤之前全部跳过

Ham*_*ish 11 ruby-on-rails

任何人都可以告诉我如何在rails 3中过滤掉之前的所有过滤器.

在rails 2.x中我们可以做到

skip_filter filter_chain
Run Code Online (Sandbox Code Playgroud)

但是rails 3中不再支持filter_chain.

谢谢

Ant*_*ton 18

试试这个

skip_filter *_process_action_callbacks.map(&:filter)
Run Code Online (Sandbox Code Playgroud)

方法_process_action_callbacks应该返回CallbackChain实例,这是一个Callback数组,并且由于Callback#filter获得了回调的名称,这有效:

before_filter :setup
_process_action_callbacks.map(&:filter) #=> [:setup]
Run Code Online (Sandbox Code Playgroud)

  • 需要为此工作提供参数:`skip_filter(*_ process_action_callbacks.map(&:filter)) (6认同)

vem*_*emv 8

需要跳过所有过滤器可能是由继承自定义ApplicationController引起的.

class ApplicationController < ActionController::Base
  # defines multiple `before_filter`s common to most controllers

class SomeController < ApplicationController
  # this controller may be fine with inheriting all filters

class AnotherController < ApplicationController
  # but this one not!
Run Code Online (Sandbox Code Playgroud)

在我的示例场景中,不是before_filter从中删除s AnotherController,而是让它继承ActionController::Base.


Rom*_*man 4

还没有尝试过,但这可能有效:

[:before, :after, :around].each {|type| reset_callbacks(type)}
Run Code Online (Sandbox Code Playgroud)