我想做以下事情:
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 =&gt;:destroy”,这会给我带来麻烦,我该如何指定?
答案 0 :(得分:0)
您可以检查记录是否未被保留和冻结:
class AdvertObserver < ActiveRecord::Observer
def after_commit advert
if not advert.persisted? and advert.frozen?
Advert.clean_total_active_cache
end
end
end