around_create回调代码什么时候执行,什么情况下我们应该使用它?
我也有这个问题,现在找到答案了:around_create
基本上可以让你同时做before_create
and an after_create
以一种方法。你必须使用yield
执行之间的保存。
class MyModel < ActiveRecord::Base
around_create :my_callback_method
private
def my_call_back_method
# do some "before_create" stuff here
yield # this makes the save happen
# do some "after_create" stuff here
end
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)