如何显示“最近访问的页面"列表 [英] How to display a list of "latest pages visited"

查看:42
本文介绍了如何显示“最近访问的页面"列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 rails 中,如何显示当前用户最近访问过的 5 个页面的列表?

In rails, how do I display a list of the lastest 5 pages the current user has visited?

我知道我可以使用 redirect_to(request.referer) 或 redirect_to(:back) 来链接到最后一页,但是如何创建实际的页面历史记录列表?

I know that I can do redirect_to(request.referer) or redirect_to(:back) to link to the last page, but how do I create an actual page history list?

它主要用于原型,因此我们不必将历史存储在数据库中.会话会做.

Its mainly for a prototype, so we dont have to store the history in the db. Session will do.

推荐答案

你可以在你的 application_controller 中放置这样的东西:

You can put something like this in your application_controller:

class ApplicationController < ActionController::Base
  before_filter :store_history

private

  def store_history
    session[:history] ||= []
    session[:history].delete_at(0) if session[:history].size >= 5
    session[:history] << request.url
  end
end

现在它存储了五个最近访问过的url

Now it store the five latest url visited

这篇关于如何显示“最近访问的页面"列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆