create called after failed saved?
I want to send request to external software whenever I am certain that a model is saved.
1) How do I determine the order in which after_create is called?
2) does it get called on a failed create?
The RAILS API documentation says:
Note that this callback is still wrapped in the transaction around save.
3) Does this mean it requires the save
to be successful before after_save
is called or does it mean that once save
is called after_save
is always triggered?
How would I learn in what order after_create is called and if it persists through a failed create?
You can read the order of callbacks here: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html
If the transaction fails, the save
event (and create
/ update
events) return false
. This will stop all later callbacks from being run. So, after_save
, after_create
/ after_update
all never get run on a failed save
(or on a failed create
/ update
).
...and the transaction gets rolled back so the database is not actually updated.
链接地址: http://www.djcxy.com/p/87650.html上一篇: 反应香蕉:国家monad或不?
下一篇: 在失败保存后创建调用?