sergserg
sergserg

Reputation: 22264

Super simple setup with impressionist, mismatch between impressionist_count and impressions_count

Using Rails 4 and Impressionist 1.5.1


I have a ProductsController and a Product model.

In my show action:

def show
  impressionist(@product, "unique view", :unique => [:session_hash])
end

In my model:

class Product < ActiveRecord::Base
  is_impressionable counter_cache: true
end 

And my Product schema:

create_table "products", force: true do |t|
  t.string   "name",                                        null: false
  t.integer  "impressions_count",           default: 0
end

And there's a mismatch between the counts:

irb(main):001:0> Product.find_by(slug: 'test').impressions_count
=> 57
irb(main):002:0> Product.find_by(slug: 'test').impressionist_count
=> 70

Upvotes: 0

Views: 103

Answers (1)

Matt Stevens
Matt Stevens

Reputation: 1124

Impressionist has its own table set up by the gem, while your addition to product table holds it own count. They are also counting two different things, hits on your show action and hits on your model.

This is the github page for the gem, skim through the usage section.

Upvotes: 0

Related Questions