diff --git a/lib/impressionist/models/active_record/impression.rb b/lib/impressionist/models/active_record/impression.rb index 710c446..f211b98 100644 --- a/lib/impressionist/models/active_record/impression.rb +++ b/lib/impressionist/models/active_record/impression.rb @@ -10,11 +10,12 @@ class Impression < ActiveRecord::Base private def update_impressions_counter_cache - impressionable_class = self.impressionable_type.constantize - - if impressionable_class.impressionist_counter_cache_options - resouce = impressionable_class.find(self.impressionable_id) - resouce.try(:update_impressionist_counter_cache) + if self.impressionable_type && self.impressionable_id + impressionable_class = self.impressionable_type.constantize + if impressionable_class.impressionist_counter_cache_options + resouce = impressionable_class.find(self.impressionable_id) + resouce.try(:update_impressionist_counter_cache) + end end end end