本文介绍了Rails:around_ * callbacks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读,但是不理解何时在之前触发 around _ * 回调之前_ *



任何帮助非常感谢。



感谢。

解决方案

/ strong>动作,那么当你想调用动作本身时,你 yield 就可以了,然后继续执行。这就是为什么它叫 周围



订单如下:之前 b $ b

因此,典型的 around_save 看起来像这样:

  def around_save 
#do something ...
yield #saves
#do something else ...
end


I have read the documentation at http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html, but don't understand when the around_* callbacks are triggered in relation to before_* and after_*.

Any help much appreciated.

Thanks.

解决方案

around_* callbacks are invoked before the action, then when you want to invoke the action itself, you yield to it, then continue execution. That's why it's called around

The order goes like this: before, around, after.

So, a typical around_save would look like this:

def around_save
   #do something...
   yield #saves
   #do something else...
end

这篇关于Rails:around_ * callbacks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 01:47