多个 after_commit 回调(Rails)的执行顺序

Sik*_*Zhu 6 ruby-on-rails-3

我最近发现after_commit在同一模型中定义的多个s 以相反的顺序被调用。例如

after_commit method1, :on => :create
after_commit method2, :on => :create
Run Code Online (Sandbox Code Playgroud)

method2之前被调用method1

它总是按 FILO 顺序调用吗?

Rai*_*ana 5

这种行为在 Rails 5.2.2.1 中仍然存在。

我的解决方案:

after_commit :after_commit_callbacks, :on => :create

def after_commit_callbacks
  method1
  method2
end
Run Code Online (Sandbox Code Playgroud)