Is it possible to determine a page request from a refresh

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

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...

Maybe, although we try not to put anything into session if we can help
it. Thanks for the idea though.

Any others?

D.

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

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