increment attribute while SHOW

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

Tom Tom 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?

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

tada’
:wink:

http://www.railsrocket.com/articles/efficiently-incrementing-model-attribute-values

Tom Tom wrote:

tada'
:wink:

http://www.railsrocket.com/articles/efficiently-incrementing-model-attribute-values

Nice. Looks like exactly what you were wanting.