# Page view count

**URL:** <https://www.ruby-forum.com/t/page-view-count/106373>\
**Category:** Rails\
**Created:** [June 9, 2007, 8:47am UTC](https://www.ruby-forum.com/t/page-view-count/106373 "2007-06-09T08:47:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@Tyche](https://www.ruby-forum.com/u/Tyche)\
**Post date:** [June 9, 2007, 8:47am UTC](https://www.ruby-forum.com/t/page-view-count/106373/1 "2007-06-09T08:47:14Z")

</div>

Hi,  
I am new to RoR and and web designing. I want to display page view  
count on my home page. How do I do that?

Many thanks,  
Tyche

---

<div class="post-metadata">

**Author:** ![Tyche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@Tyche](https://www.ruby-forum.com/u/Tyche)\
**Post date:** [June 9, 2007, 11:26am UTC](https://www.ruby-forum.com/t/page-view-count/106373/2 "2007-06-09T11:26:29Z")

</div>

Hi,

Here’s what you _could_ do, you could create a PageHit model which might  
contain: request\_uri and created\_at. Every time a page is viewed, add a  
new  
one of these objects. To ensure they are for page views, you could add  
code  
for this to the top of your layouts (application.rhtml in layouts, or  
whatever layouts your using).

ie, in application.rhtml  
\<% PageHit.create :request\_uri =\> request.request\_uri %\>

Cheers,  
James

---

<div class="post-metadata">

**Author:** ![Tyche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3da27b/32.png) [@Tyche](https://www.ruby-forum.com/u/Tyche)\
**Post date:** [June 10, 2007, 7:24am UTC](https://www.ruby-forum.com/t/page-view-count/106373/3 "2007-06-10T07:24:37Z")

</div>

James,  
This looks straight forward. But, this is only increase the load on  
the DB.  
Everytime a URL is requested, we create transcations on DB.

Is there a better way of doing this?

Another way, as far as I understand is creating a pattern in the logs  
and parse it to get the hit or view count.  
But, we can run the parser only periodically…making it non-real  
time.

Does anyone have a better way or suggest a plugin???
