Browse files

Non-restful controllers - controllers without models / resources - wo…

…uld 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.
  • Loading branch information...
1 parent 27c9352 commit 39c217a976de8184405b4bfe2bd9b03f27b08b58 @tyrauber tyrauber committed Mar 30, 2013
Showing with 6 additions and 5 deletions.
  1. +6 −5 lib/impressionist/models/active_record/impression.rb
View
11 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

0 comments on commit 39c217a

Please sign in to comment.