From 6efc0ab802a847d040af4217ea0b7c935e2ee6bb Mon Sep 17 00:00:00 2001 From: stveep Date: Mon, 7 May 2018 11:16:40 +0100 Subject: [PATCH] Set response headers to disable cache - to avoid back button emptying cart (#1213) --- app/controllers/application_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e19c9bb26b..a4bdc88b8f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base protect_from_forgery prepend_before_filter :restrict_iframes + before_filter :set_cache_headers # Issue #1213, prevent cart emptying via cache when using back button include EnterprisesHelper helper CssSplitter::ApplicationHelper @@ -152,4 +153,10 @@ class ApplicationController < ActionController::Base nil end + def set_cache_headers # https://jacopretorius.net/2014/01/force-page-to-reload-on-browser-back-in-rails.html + 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 + end