关于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


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值