简体   繁体   中英

How do I use the Impressionist gem?

I'm using the Impressionist gem.

I want to display a hit counter of one particular page, in that same view.

This is what I did:

  1. Install the gem.
  2. Run generator.
  3. Add column counter_cache to the migration.
  4. Run rake db:migrate .
  5. Add impressionist :actions=>[:show ] to the controller that I want to track impressions from.
  6. Add is_impressionable :counter_cache => true to the model pertaining to the controller above.
  7. Restart server.

I have two questions:

  1. Why doesn't the counter_cache number get increased for each impression (and each respective record)?
  2. Is there any method I can use in the view to display the hit count, or should I craft my own query?

There is a method to show how much hits:

<%= @model_instance.impressionist_count %> views

Put this in your view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM