impressionist/app/models/impression.rb

16 lines
425 B
Ruby
Raw Normal View History

2011-02-04 04:13:41 +00:00
class Impression < ActiveRecord::Base
belongs_to :impressionable, :polymorphic=>true
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
end
2011-02-04 04:13:41 +00:00
end