Ruby on rails 3 同一方法的多个after_commit

Ruby on rails 3 同一方法的多个after_commit,ruby-on-rails-3,callback,Ruby On Rails 3,Callback,如何指定该方法的多个回调? 错误: /activesupport-3.2.13/lib/active_support/callbacks.rb:404: syntax error, unexpected '[', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END ...(transaction_include_action?(:[:create, :destroy])) 出于某些原因,回调也不会使

如何指定该方法的多个回调?

错误:

/activesupport-3.2.13/lib/active_support/callbacks.rb:404: syntax error, unexpected '[', expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
...(transaction_include_action?(:[:create, :destroy]))
出于某些原因,回调也不会使用以下命令执行:

after_commit :assign_awards, on: :create
after_commit :assign_awards, on: :destroy
只有当我使用两种不同的方法时,它才会起作用,如:

after_commit :assign_awards_create, on: :create
after_commit :assign_awards_destroy, on: :destroy

private

def assign_awards_create
  AwardsWorker.perform_async(self.id, self.class.name, self.user_id)
end

def assign_awards_destroy
  AwardsWorker.perform_async(self.id, self.class.name, self.user_id)
end

嗯,这个答案正好相反:
.

可能是您使用的Rails版本有问题

after_commit :assign_awards_create, on: :create
after_commit :assign_awards_destroy, on: :destroy

private

def assign_awards_create
  AwardsWorker.perform_async(self.id, self.class.name, self.user_id)
end

def assign_awards_destroy
  AwardsWorker.perform_async(self.id, self.class.name, self.user_id)
end