Wilhelm Longshanks
2009-Dec-29 00:38 UTC
Showing the items visited for a non-logedin users
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? - Wil -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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. -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.