如何从多个地方重定向到上一页? [英] How to redirect to previous page from multiple places?

查看:73
本文介绍了如何从多个地方重定向到上一页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能在这里错过了一些非常简单的内容...

I'm likely missing something really simple here...

说我有一个名为 Option 的模型。然后,我在视图中列出这些选项,并带有启用/禁用按钮,这些按钮会导致控制器动作,然后该控制器动作将启用或禁用该特定的 Option

Say I have model called Option. I then list these options in the view, with Enable / Disable buttons that lead to a controller action which then enables or disables that particular Option.

如果列表仅位于一个位置,我知道只需要调用 redirect_to render 让用户返回到正确的页面,因为只有一个页面。

If the list is only in one place, I know just to call redirect_to or render to have the user go back to correct page, since there's only one.

如果同一列表位于多个位置怎么办?

What if the same list is in multiple places?

意思是,如果只有一个具有启用/禁用操作的控制器,我该如何使该控制器使用户返回他们单击按钮的页面?

Meaning, if there's only one controller with enable / disable actions, how do I make that controller "return" the user to the page where they clicked the button?

我曾考虑过将前一页保留在会话变量中,但是这似乎是错误的。

I thought about keeping the previous page in a session variable or something but that seems wrong.

推荐答案

您可以使用 redirect_to:back request.env ['HTTP_REFERER']

这篇关于如何从多个地方重定向到上一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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