了解 Rails 4 中的 after_update 回调 [英] Understanding after_update callback in Rails 4

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

问题描述

我有一个带有 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆