before_filter :browse_product_history #浏览历史记录 # 存 # 调用cookies[:browse_product_history]返回chemical的历史浏览序列(从新到旧),用/隔开, def browse_product_history cookies.delete :browse_chemicals_history if cookies[:browse_product_history] =~ /EBD/ if params[:controller] == "products" && params[:action] == "show" product_id = params[:id] if cookies[:browse_product_history].blank? history = product_id + "/" cookies[:browse_product_history] = { value: history, expires: 20.years.from_now } else history_array = cookies[:browse_product_history].split("/") if history_array.size < 6 if history_array.include?(product_id) history_array.delete(product_id) history_array.unshift(product_id) else history_array.unshift(product_id) end else if history_array.include?(product_id) history_array.delete(product_id) history_array.unshift(product_id) else history_array.pop history_array.unshift(product_id) end end history = history_array * "/" cookies[:browse_product_history] = { value: history, expires: 20.years.from_now } end end end 取: @history_browse_product_cases = cookies[:browse_product_history].split("/") @product = Product.where(id: @history_browse_product_cases)
cookies记录用户浏览商品
http://www.schooltop.net/blogs/292
猜你喜欢
转载自schooltop.iteye.com/blog/2310827
今日推荐
周排行