Rails: impressionist_count on a relationship table -
i'm trying use impressionist gem track visits on relation. write method works well:
@document.publications.each |publication| impressionist(publication) end
i have has_many, :through
relation (simplified here works fine):
class document has_many :components, :through => :publications end
i'm running issue writing query relevant impressions based on component. failing code presently looks this:
<% document.components.each |component| %> <%= component.publications.where(:document_id => document.id).impressionist_count %> <% end %>
i no method error so:
undefined method 'impressionist_count' #<activerecord::relation:blah
i know i'm writing failing code incorrectly i'm struggling find correct way write it.
you need set-up :counter_cache in association
watch video, it's explained http://railscasts.com/episodes/23-counter-cache-column
Comments
Post a Comment