如何实现到来自页面的后退链接 [英] How implement the Back Link to the page from which comes from

查看:47
本文介绍了如何实现到来自页面的后退链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有关联的应用程序,并将对页面进行分页.

I have an application with associations and will pagination the pages.

主对象cat_list"的索引页面显示了关联data_lists"的链接.索引页也有will_pagination"的分页

The index page from the main object "cat_list" shows links to the association "data_lists". The index page has also pagination with "will_paginate"

  1. 我显示例如 page=3 "/cat_lists?page=3"
  2. 我点击了data_lists"的链接,例如/cat_lists/8984/data_lists"

此索引页面显示了一个包含编辑、销毁和新建链接的 data_lists 列表.现在有一个指向 cat_lists 索引页面的反向链接/cat_lists"

This index page shows a list of data_lists with Edit, Destroy and a New link. And a Back Link to the cat_lists index page now "/cat_lists"

实现这些功能的最佳实践是什么,即返回链接现在来自哪个页面?

What is the best practice to implement the features, that the Back Link now the page from which comes from?

推荐答案

我通常在 session 中记录历史,然后通过 redirect_to back(无冒号)

I usually record the history in the session and then call it via redirect_to back (no colon)

def index
  ... do your stuff ...
  record_history
end

protected

  def record_history
    session[:history] ||= []
    session[:history].push request.url
    session[:history] = session[:history].last(10) # limit the size to 10
  end

  def back
    session[:history].pop
  end

请注意,这仅适用于 GET 请求.

Note that this only works for GET requests.

这篇关于如何实现到来自页面的后退链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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