From 39c217a976de8184405b4bfe2bd9b03f27b08b58 Mon Sep 17 00:00:00 2001 From: Ty Rauber Date: Sat, 30 Mar 2013 13:00:46 -0700 Subject: [PATCH] Non-restful controllers - controllers without models / resources - would cause impressionist to throw an error on impression create, because it was unable to update the model counter cache due to lack of an impressionable_type and impressionable_id. An if statement around the counter-cache method on impressionable_type and impressionable_id solves this. --- lib/impressionist/models/active_record/impression.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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