we''re trying to add a feature where we log a view each time a user looks at a particular item (it''s being logged as a database record against the item id). Problem is, if that user refreshes the page we don''t want it to register as another view. Users may or may not be logged in when viewing items so we can''t log it against the user id. Any ideas? D --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
PeteSalty wrote:> we''re trying to add a feature where we log a view each time a user > looks at a particular item (it''s being logged as a database record > against the item id). > Problem is, if that user refreshes the page we don''t want it to > register as another view. Users may or may not be logged in when > viewing items so we can''t log it against the user id.Stash its id in the session: session[:viewed] ||= {} unless session[:viewed][id] add_one_eyeball(id) session[:viewed][id] = true end There might be a tighter way to do that... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
PeteSalty
2008-Sep-09 05:22 UTC
Re: Is it possible to determine a page request from a refresh
Maybe, although we try not to put anything into session if we can help it. Thanks for the idea though. Any others? D. On Sep 8, 1:57 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> PeteSalty wrote: > > we''re trying to add a feature where we log a view each time a user > > looks at a particular item (it''s being logged as a database record > > against the item id). > > Problem is, if that user refreshes the page we don''t want it to > > register as another view. Users may or may not be logged in when > > viewing items so we can''t log it against the user id. > > Stash its id in the session: > > session[:viewed] ||= {} > unless session[:viewed][id] > add_one_eyeball(id) > session[:viewed][id] = true > end > > There might be a tighter way to do that...--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mukund
2008-Sep-09 10:10 UTC
Re: Is it possible to determine a page request from a refresh
Can you muck around with Javascript instead? http://www.onjava.com/pub/a/onjava/2005/10/26/ajax-handling-bookmarks-and-back-button.html?page=4 On Sep 9, 10:22 am, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Maybe, although we try not to put anything into session if we can help > it. Thanks for the idea though. > > Any others? > > D. > > On Sep 8, 1:57 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > PeteSalty wrote: > > > we''re trying to add a feature where we log a view each time a user > > > looks at a particular item (it''s being logged as a database record > > > against the item id). > > > Problem is, if that user refreshes the page we don''t want it to > > > register as another view. Users may or may not be logged in when > > > viewing items so we can''t log it against the user id. > > > Stash its id in the session: > > > session[:viewed] ||= {} > > unless session[:viewed][id] > > add_one_eyeball(id) > > session[:viewed][id] = true > > end > > > There might be a tighter way to do that...--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Olliver
2008-Sep-10 01:44 UTC
Re: Is it possible to determine a page request from a refresh
If you don''t want to store anything in the session, how about checking the referrer url in your controller action? def show @item = Item.find(params[:id]) dont_log_page_view = request.env["HTTP_REFERER"] =~ /\/items\/ #{@item.id}/ ... end That will check to see if the request for the item has come from the same item page. (Modify the regexp as needed depending on your route) Some browser plugins stop the browser from sending the http referrer in the request, but as far as I know it''s usually only the paranoid who use those. Jeremy On Sep 9, 8:45 am, PeteSalty <petesa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> we''re trying to add a feature where we log a view each time a user > looks at a particular item (it''s being logged as a database record > against the item id). > Problem is, if that user refreshes the page we don''t want it to > register as another view. Users may or may not be logged in when > viewing items so we can''t log it against the user id. > > Any ideas? > > D--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---