2011-02-04 04:13:41 +00:00
|
|
|
class Impression < ActiveRecord::Base
|
|
|
|
belongs_to :impressionable, :polymorphic=>true
|
2011-10-29 22:24:57 +00:00
|
|
|
|
|
|
|
after_save :update_impressions_counter_cache
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_impressions_counter_cache
|
2011-10-31 17:02:31 +00:00
|
|
|
impressionable_class = self.impressionable_type.constantize
|
|
|
|
|
2011-10-31 18:18:46 +00:00
|
|
|
if impressionable_class.counter_cache_options
|
2011-10-31 17:02:31 +00:00
|
|
|
resouce = impressionable_class.find(self.impressionable_id)
|
|
|
|
resouce.try(:update_counter_cache)
|
|
|
|
end
|
2011-10-29 22:24:57 +00:00
|
|
|
end
|
2011-02-04 04:13:41 +00:00
|
|
|
end
|