简体   繁体   English

我如何使用印象派宝石?

[英]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. 将列counter_cache添加到迁移中。
  4. Run rake db:migrate . 运行rake db:migrate
  5. Add impressionist :actions=>[:show ] to the controller that I want to track impressions from. impressionist :actions=>[:show ]添加到我要从中跟踪印象的控制器。
  6. Add is_impressionable :counter_cache => true to the model pertaining to the controller above. is_impressionable :counter_cache => true添加到与上述控制器有关的模型。
  7. Restart server. 重新启动服务器。

I have two questions: 我有两个问题:

  1. Why doesn't the counter_cache number get increased for each impression (and each respective record)? 为什么每次展示(以及每个记录)的counter_cache数量都没有增加?
  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. 把它放在您的观点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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