I have a site that tracks video views... every time the controller is called. One could flood their own video views with some heavy F5ing.
How to make it so a view counts or a method runs only once per session?
def show
new_views = @video.views + 1
@video.update_attributes(:views => new_views)
end
You can create a session variable, probably upon login, like :
session[:is_logged] = 1
Then, every time you are about to increment the counter, just check this variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With