From a8843c1036d3dbdb44ca31b223f4991ff2bdbeff Mon Sep 17 00:00:00 2001 From: Steven Hancock Date: Mon, 2 Apr 2012 21:13:16 -0700 Subject: [PATCH] Fix JSON caching regression Disable jQuery's AJAX caching to prevent the browser's back button from dumping the stream in JSON format. Includes a test for the jquery_include_tag helper to ensure that the necessary line of javascript doesn't go missing again. closes #3094 --- app/helpers/application_helper.rb | 1 + spec/helpers/application_helper_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e611a2cbd..92ec5f6f9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -48,6 +48,7 @@ module ApplicationHelper buf << [ javascript_include_tag('jquery') ] end buf << [ javascript_include_tag('jquery_ujs') ] + buf << [ javascript_tag("jQuery.ajaxSetup({'cache': false});") ] buf.join("\n").html_safe end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 7a34f9b89..19079a273 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -78,5 +78,9 @@ describe ApplicationHelper do it 'inclues jquery_ujs.js' do jquery_include_tag.should match(/jquery_ujs\.js/) end + + it "disables ajax caching" do + jquery_include_tag.should match(/jQuery\.ajaxSetup/) + end end end