Rails:around_* 回调 [英] Rails: around_* callbacks
本文介绍了Rails:around_* 回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已阅读 http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html 上的文档,但不明白什么时候 around_*
回调与 before_*
和 after_*
相关.
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_*
.
非常感谢任何帮助.
谢谢.
推荐答案
around_*
回调在动作之前被调用,然后当你想调用动作本身时,你yield
给它,然后继续执行.这就是为什么它被称为around
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
顺序是这样的:before
,around
,after
.
因此,典型的 around_save
如下所示:
So, a typical around_save
would look like this:
def around_save
#do something...
yield #saves
#do something else...
end
这篇关于Rails:around_* 回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文