Reputation: 17834
I want to count the number of visits on my blog? Can someone please suggest the overall method to implement this feature?
Upvotes: 0
Views: 1460
Reputation: 7614
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:
Upvotes: 0
Reputation: 5734
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.
Upvotes: 3