# Increment attribute while SHOW

**URL:** <https://www.ruby-forum.com/t/increment-attribute-while-show/186627>\
**Category:** Rails\
**Created:** [April 10, 2010, 12:01am UTC](https://www.ruby-forum.com/t/increment-attribute-while-show/186627 "2010-04-10T00:01:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [April 10, 2010, 12:01am UTC](https://www.ruby-forum.com/t/increment-attribute-while-show/186627/1 "2010-04-10T00:01:36Z")

</div>

hi,

im trying to do:

def show  
@advisor = Advisor.find(params[:id])  
@advisor.reviews = @advisor.reviews + 1 #reviews is just an  
integer  
@advisor.save!  
…

how can i implement a “show”-counter?

thx

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [April 10, 2010, 1:44am UTC](https://www.ruby-forum.com/t/increment-attribute-while-show/186627/2 "2010-04-10T01:44:05Z")

</div>

Tom T. wrote:

> def show  
> @advisor = Advisor.find(params[:id])  
> @advisor.reviews = @advisor.reviews + 1 #reviews is just an  
> integer  
> @advisor.save!  
> …  
> how can i implement a “show”-counter?

The first problem I see is that the “show” action typically uses a GET  
request. GET requests should be both idempotent and safe. Imagine what  
would happen if a user were to navigate to your show page and then just  
repeatedly refreshed the page. Every refresh would be a new request  
causing your count to be unreliable. For instance, if you were relying  
on this count to judge the popularity of a particular item it would be  
trivial for an end user to artificially promote whatever item they wish.

I don’t know what your end goal is for such a feature, but generally  
speaking, such information is usually gleaned from web logs, rather than  
being implemented inside the application.

There are also many web log analyzers available that people use to  
monitor web site usage. These will typically generate more useful  
reports than what you would care to generate yourself.

For example, I would expect a good web log analyzer to show typical  
navigation paths through an web site. This information could be used to  
detect whether a user has navigated to the page from a different page,  
or simply refreshed the same page. This might indicate attempts to  
artificially raise the popularity of a given page. It might also  
indicate a problem with the page. Maybe the page is slow to respond  
prompting the user to attempt to “fix” it by pressing reload.

Just some thoughts. Were you having a particular problem with your  
implementation, or just looking for advice and suggestions?

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [April 10, 2010, 2:39am UTC](https://www.ruby-forum.com/t/increment-attribute-while-show/186627/3 "2010-04-10T02:39:07Z")

</div>

Hi Robert, thx 4 ur time and ur answer. im aware of analyzer(& their  
theory)  
as well of recording the users “browsing-behaviour-strategies”.

in that case, its a secured environment (users have to be logged in  
etc…)  
and if they do the SHOW-action, they will see a full profile of other  
registered users. so my question was just simple: why is it not  
incrementing?  
thx  
again  
best tom

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [April 10, 2010, 3:13am UTC](https://www.ruby-forum.com/t/increment-attribute-while-show/186627/4 "2010-04-10T03:13:16Z")

</div>

Tom T. wrote:

> tada’  
> 😉
> 
> [Railsrocket.com is for sale | HugeDomains](http://www.railsrocket.com/articles/efficiently-incrementing-model-attribute-values)

Nice. Looks like exactly what you were wanting.

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [April 10, 2010, 2:47am UTC](https://www.ruby-forum.com/t/increment-attribute-while-show/186627/5 "2010-04-10T02:47:20Z")

</div>

tada’  
😉

> **[Railsrocket.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=railsrocket.com)**
>
> Easy, affordable options for you to obtain the domain you want. Safe and secure shopping.
