ruby-on-rails - 闪光[:notice] is shown on browser back again

标签 ruby-on-rails flash notice

嘿嘿
我有个问题:
我在我的 rails 应用程序中使用 flash[:notice]。
用户来到页面并创建一个新对象。快闪消息显示“已创建”。现在他点击页面上的链接。如果他使用浏览器的“返回”按钮回来,则会再次显示快速消息。
flash.now[:notice] 也不起作用(我认为并且我测试过)。问题是文件没有新的渲染。

你有什么想法可以防止这种情况发生吗?谢谢!

最佳答案

问题不在于 flash 变量,而在于浏览器缓存。这个解决方案对我使用 Rails 3.2 效果很好(来自这个线程 How to prevent browser page caching in Rails ):

在 application_controller.rb 中:

before_filter :set_cache_buster

  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"] = "Fri, 01 Jan 1990 00:00:00 GMT"
  end

关于ruby-on-rails - 闪光[:notice] is shown on browser back again,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3370392/

相关文章:

ruby-on-rails - 如何对序列化属性执行包含验证?

jquery - 嵌入式 YouTube 视频不适用于溢出 :hidden

actionscript-3 - 八哥 Sprite 内部空白空间的触摸事件

php - 检查 Variable 是否存在并且 === true

ruby-on-rails - define_method 如何使用在其外部初始化的变量

ruby-on-rails - has_many 与多态关联中的 class_name

html - Textarea 不通过表单发送值

javascript - 我试图让这段代码在 Visual Studio 2010 中工作,它在 Firefox 浏览器中显示我的 "SWFObject is undefined"。 swfobject.js 是 2.2

php - 基于 Woocommerce 中用户总购买量的自定义购物车通知

php - 使用 CURLOPT_POSTFIELDS 时数组 2 字符串转换