0
如何爲該方法指定多個回調? 用於同一方法的多個after_commit
after_commit :assign_awards, on: [:create, :destroy]
private
def assign_awards
AwardsWorker.perform_async(self.id, self.class.name, self.user_id)
end
錯誤:
/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