Execution order of multiple after_commit callbacks (Rails)

不打扰是莪最后的温柔 提交于 2020-03-21 19:06:23

问题


I recently found that multiple after_commits defined in the same model get called in reverse order. For example

after_commit method1, :on => :create
after_commit method2, :on => :create

method2 gets called before method1.

Is it always called in FILO order?


回答1:


This behaviour is still present in Rails 5.2.2.1.

My solution:

after_commit :after_commit_callbacks, :on => :create

def after_commit_callbacks
  method1
  method2
end


来源:https://stackoverflow.com/questions/30625790/execution-order-of-multiple-after-commit-callbacks-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!