ruby-on-rails - 无法阻止浏览器缓存页面
问题描述
我试图阻止浏览器在表单页面上缓存并阻止用户在提交后返回。
application_controller.rb
protected
def set_no_cache
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
另一个控制器.rb
before_filter :set_no_cache, only: [:new, :edit]
例如,在“编辑”操作上添加一个时byebug
,我看到标题正确更改:
(byebug) headers
{"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "Cache-Control"=>"no-cache, no-store, max-age=0, must-revalidate", "Pragma"=>"no-cache", "Expires"=>"Fri, 01 Jan 1990 00:00:00 GMT"}
但这对我不起作用,我在 Ubuntu 上尝试了 Chrome、Opera 和 Safari 浏览器。
解决方案
推荐阅读
- java - 使用spring中hibernate事务的集成控制
- keras - 我应该如何调试
- pine-script - Pine Script (TradingView) - 如何将止损移动到获利水平
- python - 使用 python pandas drop 函数时显示 Keyerror
- python-3.x - 如何通过boto3设置keypair名称创建elasticbeanstalk环境
- python-3.x - 光gbm || ValueError:Series.dtypes 必须是 int、float 或 bool
- openwhisk - openwhisk ansible setup.yml 失败,出现错误“ansible/_distribution 未定义”
- java - Tomcat9 - 限制 STDOUT 和 STDERR 的大小或文件轮换
- javascript - Django 表单未使用 ajax 调用接收表单数据
- arrays - 如何将图形节点之间的连接数组转换为具有连接的二维节点数组?