Skip to content
Browse files

Remove caching's dependency on view_context. Also, make it so that th…

…e layout is always rendered the same way (so that layout dependencies on the action actually being rendered aren't masked on the first render)
  • Loading branch information...
1 parent d8c7efe commit 523d0f3700f5bb68cdd3d549eaad63d8a88c2aef Carlhuda committed Mar 18, 2010
Showing with 26 additions and 14 deletions.
  1. +12 −4 actionpack/lib/abstract_controller/layouts.rb
  2. +14 −10 actionpack/lib/action_controller/caching/actions.rb
View
16 actionpack/lib/abstract_controller/layouts.rb
@@ -185,6 +185,8 @@ module LayoutConditions
# ==== Returns
# Boolean:: True if the action has a layout, false otherwise.
def action_has_layout?
+ return unless super
+
conditions = _layout_conditions
if only = conditions[:only]
@@ -297,6 +299,16 @@ def _normalize_options(options)
end
end
+ attr_writer :action_has_layout
+
+ def initialize(*)
+ @action_has_layout = true
+ end
+
+ def action_has_layout?
+ @action_has_layout
+ end
+
private
# This will be overwritten by _write_layout_method
@@ -353,9 +365,5 @@ def _default_layout(require_layout = false)
def _include_layout?(options)
(options.keys & [:text, :inline, :partial]).empty? || options.key?(:layout)
end
-
- def action_has_layout?
- true
- end
end
end
View
24 actionpack/lib/action_controller/caching/actions.rb
@@ -80,21 +80,18 @@ module ClassMethods
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)
around_filter ActionCacheFilter.new(cache_options), filter_options
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 @@ def filter(controller)
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

0 comments on commit 523d0f3

Please sign in to comment.
Something went wrong with that request. Please try again.