0

我想做以下事情:

after_commit :on => :destroy do
  Advert.clean_total_active_cache
end

但以类似观察者的方式:

class AdvertObserver < ActiveRecord::Observer
  def after_commit advert
    Advert.clean_total_active_cache
  end
end

这是“:on =>:destroy”,这给我带来了麻烦,我该如何指定?

4

1 回答 1

0

您可以检查记录是否没有被持久化和冻结:

class AdvertObserver < ActiveRecord::Observer
  def after_commit advert
    if not advert.persisted? and advert.frozen?
      Advert.clean_total_active_cache
    end
  end
end
于 2012-08-07T09:51:15.023 回答