了解Rails 4中的after_update回调 [英] Understanding after_update callback in Rails 4
问题描述
我有一个带有 after_update
回调的Rails对象,该回调将记录发送到队列。问题是我发现有时队列的处理速度比对象实际更新的速度快。
I have a Rails object with after_update
callback that sends a record to a queue. And the problem is that I noticed sometimes the queue is being processed faster than the object is actually being updated.
我的问题是: after_update
不是在对象更新结束后调用,而是在它开始时调用?如果我只想在成功完成后做某事,该怎么做?
My question: is after_update
called not after the object updating ended, but when it started? What callback I need if I want to do something with it only after update is successful?
推荐答案
在事务块内调用 after_save
, after_create
, after_update
,因此它们将在执行SQL语句之前执行。
after_save
, after_create
, after_update
are called within the transaction block, so they will be executed before executing the SQL statement.
如果要在语句执行完成后执行某些操作,则应使用 after_commit 回调。
If you want to do something when the statement execution is completed, you should use after_commit callback.
这篇关于了解Rails 4中的after_update回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!