문제

Is it possible to skip a before filter in using skip_before_filter when the before_filter is defined with a block. For example:

class ApplicationController < ActionController::Base
  before_filter do |controller|
    # filter stuff
  end
end

I know, that is it possible using the "normal" way of defining the filter with a method name.

도움이 되었습니까?

해결책 2

Its most definitely not possible. From the documentation:

Note that skipping uses Ruby equality, so it’s impossible to skip a callback defined using an anonymous proc using #skip_filter

http://apidock.com/rails/AbstractController/Callbacks/ClassMethods/skip_action_callback

다른 팁

I actually found a way around this using an if option with a method. Use

class ApplicationController < ActionController::Base
  before_filter(:if => :use_filter?) do |controller|
    # filter stuff
  end

  private

  def use_filter?
    true
  end
end

class OtherController < ApplicationController
  private

  def use_filter?
    false
  end
end

:D

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top