Ruby on rails 3 多个after_commit回调(Rails)的执行顺序

Ruby on rails 3 多个after_commit回调(Rails)的执行顺序,ruby-on-rails-3,Ruby On Rails 3,我最近发现,在同一个模型中定义的多个after_commits会以相反的顺序被调用。比如说 after_commit method1, :on => :create after_commit method2, :on => :create method2在method1之前被调用 它总是按顺序叫吗 Rails 5.2.2.1中仍然存在这种行为 我的解决方案: after_commit :after_commit_callbacks, :on => :create def a

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

after_commit method1, :on => :create
after_commit method2, :on => :create
method2
method1
之前被调用


它总是按顺序叫吗

Rails 5.2.2.1中仍然存在这种行为

我的解决方案:

after_commit :after_commit_callbacks, :on => :create

def after_commit_callbacks
  method1
  method2
end

为什么不在提交method1,method2之后编写
:on=>:create
,这样它们将按照您感兴趣的方式执行,当我尝试像您提到的那样在一行中编写它们时,
method2
仍然在
method1
之前被调用。我的rails版本是
3.0.20.13
。那么,这种行为是否已修复?是否有一些文档支持这一点?有一个GH问题报告了这种行为:(但它已关闭)。在Rails 6.0.3.3中仍然可以看到这一点