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:
parent
27c9352a5e
commit
39c217a976
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue