From 3deb60e6b492b5b944e7e6ead3531ad4e412f56d Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 18 Mar 2010 13:45:50 -0700 Subject: @layout is a confusing name... use @cache_layout --- actionpack/lib/action_controller/caching/actions.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller/caching/actions.rb') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 35111a4b92..3e5240a0ef 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -112,7 +112,7 @@ module ActionController #:nodoc: class ActionCacheFilter #:nodoc: def initialize(options, &block) - @cache_path, @store_options, @layout = + @cache_path, @store_options, @cache_layout = options.values_at(:cache_path, :store_options, :layout) end @@ -126,10 +126,10 @@ module ActionController #:nodoc: cache_path = ActionCachePath.new(controller, path_options || {}) if cache = controller.read_fragment(cache_path.path, @store_options) - controller._render_cache_fragment(cache, cache_path.extension, @layout == false) + controller._render_cache_fragment(cache, cache_path.extension, @cache_layout == false) else yield - controller._save_fragment(cache_path.path, @layout == false, @store_options) + controller._save_fragment(cache_path.path, @cache_layout == false, @store_options) end end end -- cgit v1.2.3 From 523d0f3700f5bb68cdd3d549eaad63d8a88c2aef Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 18 Mar 2010 14:55:13 -0700 Subject: Remove caching's dependency on view_context. Also, make it so that the layout is always rendered the same way (so that layout dependencies on the action actually being rendered aren't masked on the first render) --- .../lib/action_controller/caching/actions.rb | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'actionpack/lib/action_controller/caching/actions.rb') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index 3e5240a0ef..e89bf64026 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -80,6 +80,7 @@ module ActionController #:nodoc: def caches_action(*actions) return unless cache_configured? options = actions.extract_options! + options[:layout] = true unless options.key?(:layout) filter_options = options.extract!(:if, :unless).merge(:only => actions) cache_options = options.extract!(:layout, :cache_path).merge(:store_options => options) @@ -87,14 +88,10 @@ module ActionController #:nodoc: end end - def _render_cache_fragment(cache, extension, layout) - render :text => cache, :layout => layout, :content_type => Mime[extension || :html] - end - - def _save_fragment(name, layout, options) + def _save_fragment(name, options) return unless caching_allowed? - content = layout ? view_context.content_for(:layout) : response_body + content = response_body write_fragment(name, content, options) end @@ -125,12 +122,19 @@ module ActionController #:nodoc: cache_path = ActionCachePath.new(controller, path_options || {}) - if cache = controller.read_fragment(cache_path.path, @store_options) - controller._render_cache_fragment(cache, cache_path.extension, @cache_layout == false) - else + body = controller.read_fragment(cache_path.path, @store_options) + + unless body + controller.action_has_layout = false unless @cache_layout yield - controller._save_fragment(cache_path.path, @cache_layout == false, @store_options) + controller.action_has_layout = true + body = controller._save_fragment(cache_path.path, @store_options) end + + body = controller.render_to_string(:text => cache, :layout => true) unless @cache_layout + + controller.response_body = body + controller.content_type = Mime[cache_path.extension || :html] end end -- cgit v1.2.3 From f868c2afa9190604015b6c5fd3bcc58371f03570 Mon Sep 17 00:00:00 2001 From: wycats Date: Fri, 19 Mar 2010 18:56:06 -0700 Subject: response_body is an Array in 1.9, so an Array was being pushed onto the cache --- actionpack/lib/action_controller/caching/actions.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib/action_controller/caching/actions.rb') diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index e89bf64026..43ddf6435a 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -92,6 +92,8 @@ module ActionController #:nodoc: return unless caching_allowed? content = response_body + content = content.join if content.is_a?(Array) + write_fragment(name, content, options) end -- cgit v1.2.3