سؤال

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