嘿嘿
我有个问题:
我在我的 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/