Hi - I would like to implement a feature similar to “Items you have
visited” in Amazon.
The requirement is that the feature is also available for those who
are not logged-in.
I have a User and Item models. I use Rails-default session storage.
I do not need when exactly each item page is visited, but I need to
keep the order of them
so that I can show the most recently visited item on top of the list.
Do I need to create and save every user and save the history of
visited items in the database?
–
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Wilhelm Longshanks wrote:
Hi - I would like to implement a feature similar to “Items you have
visited” in Amazon.
The requirement is that the feature is also available for those who
are not logged-in.
I have a User and Item models. I use Rails-default session storage.
I do not need when exactly each item page is visited, but I need to
keep the order of them
so that I can show the most recently visited item on top of the list.
Do I need to create and save every user and save the history of
visited items in the database?
No. If you just save the ids of the last viewed items in an array and
keep this array short there should be no problem with the cookie-based
sessions.
Just do something like:
session[:last_viewed] ||= []
session[:last_viewed] =
session[:last_viewed].unshift(@item.id).uniq[0,5]
With this you have the ids of the last (max. 5) @item(s) in
session[:last_viewed] in descending order.
Hope this helps, T.