views:

100

answers:

2

How to show Number of Views (like : This link/page has been viewed 68 times) in rails? I sthere any gem or plugin available for it ?

+1  A: 

If you are following the usual MVC pattern, then a View is a representation of the object model and the best way to track a view count would be to simply add a 'number of times viewed' counter to the table.

+1  A: 

Simply add a counter column to your Model, and increment it whenever the page is hit in the controller. As simple as this is, there are some design issues:

  • Page caching will affect your stats. In this case, you can still use Ajax on your page to register the hit. (Not much different than how google analytics works.)

  • Do your pages already have an obvious relationship to a Model? If they are user profile pages for example, put the counter in the Profile model.

Walt Gordon Jones