On Fri, Dec 5, 2008 at 5:09 PM, Petan Cert
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> I''ve made a really simple page views counter.
>
> def show
> @post = Post.find......
> addcount = @post.views += 1
> @post.update_attribute "views", addcount
You don''t need the extra variable.
@post.update_attribute ''views'', @post.views + 1
> end
>
> Its working fine, but if someone hold the F5 key, it keeps counting and
> counting. Which is not a really good. Is there a way how to force the
> counter to not keep counting while someone is holding the F5 key?
Store their IP address and a timestamp and then don''t count more views
from that same IP for a while.
For the IP address use request.env[ ''HTTP_X_FORWARDED_FOR'' ]
if your
Rails app is behind a proxy, or request.env[ ''REMOTE_ADDR'' ]
if it''s
not.
--
Greg Donald
http://destiney.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---