阻止用户返回并查看以前提交的表单Rails

问题描述 投票:1回答:1

我有一个付款页面,当用户提交时,它会捕获付款并指向感谢页面。问题是当用户点击回来时,浏览器会将它们带回到之前提交的页面,其中包含付款表单和所有内容。

如何阻止用户访问上一页?

谢谢

html ruby-on-rails-3
1个回答
4
投票

@James,将此方法放在应用程序控制器中,并在before_action回调上调用此方法,如 -

before_action:set_cache_buster

然后在受保护的方法中定义操作,如 - >

protected

def set_cache_buster
  response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
  response.headers["Pragma"] = "no-cache"
  response.headers["Expires"] = "#{1.year.ago}"
end

为此,我们只需要使用适当的HTTP标头禁用浏览器缓存。这是秘密:

Cache-Control:no-cache,max-age = 0,must-revalidate,no-store

单独来看,这些Cache-Control属性中的每一个似乎都会阻止缓存。实际上,在大多数浏览器中,no-cache和no-store通常是可互换的。但是,对于后退按钮缓存,Firefox将仅在未指定存储时禁用此缓存。为了安全起见并保证跨浏览器兼容性,您应该使用所有四个属性。

有关更多信息,请参阅链接 - Difference between Pragma and Cache-control headers?

希望你喜欢这个。

具体页面 - >

1)在特定页面上添加该回调,仅使用 - >选项

before_action:set_cache_buster,仅:[:your_action_name]

© www.soinside.com 2019 - 2024. All rights reserved.