关于around_filter 的调用

def call_filter(chain, index)

        return (performed? || perform_action_without_filters) if index >= chain.size

        filter = chain[index]

        return call_filter(chain, index.next) if self.class.filter_excluded_from_action?(filter,action_name)



        halted = false

        filter.call(self) do

          halted = call_filter(chain, index.next)

        end

        halt_filter_chain(filter.filter, :no_yield) if halted == false unless @before_filter_chain_aborted

        halted

      end


    在control 的 around_filter的函数和代码块中,总是会需要yield, 那么这个yield 执行的参数是什么呢,就是上面的 call_filter(chain,index.next). 通过这几行代码,就可以解释如下代码的调用结果
"---------test_one-------------"
"-----------test_two-----------"
"--------end of test_two-------"
"---------end of test_one------"

around_filter :test_one
  around_filter :test_two

  def test_one
    p "---------test_one-------------"
    yield
    p "---------end of test_one------"
  end

  def test_two
    p "-----------test_two-----------"
    yield
    p "--------end of test_two-------"
  end


 

你可能感兴趣的:(filter)