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.

This commit is contained in:
Ty Rauber 2013-03-30 13:00:46 -07:00
parent 27c9352a5e
commit 39c217a976
1 changed files with 6 additions and 5 deletions

View File

@ -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