I want to count the number of visits on my blog? Can someone please suggest the overall method to implement this feature?
Asked
Active
Viewed 1,411 times
0
-
1duplicate of http://stackoverflow.com/questions/4815713/simple-hit-counter-for-page-views-in-rails – Rajarshi Das Sep 11 '13 at 06:31
3 Answers
3
It is just an idea. You can add a count_view
column in the database into blogs
table with default value 0.
And in the show action of BlogsController add the following code
def show
@blog = Blog.where('id = ?', params[:id]).first
@blog.update_column('count_view', @blog.count_view + 1) if @blog.present?
end
You can modify this logic as per your requirement.

Bachan Smruty
- 5,686
- 1
- 18
- 23
0
You could also use an existing (free) analytics solutions if you want to get much more data than the number of times the action was called (please note that if the same user refreshes the browser 5 times, you get 5 hits):
http://www.google.com/analytics/
Using these you can get data like unique visitors, referral URL, locations data, browser, OS, and a lot of different stuff to make informed decisions. There are several other options (paid, free, real time) available as well:

amit_saxena
- 7,450
- 5
- 49
- 64