aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2010-03-14 18:55:13 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-03-14 19:09:32 -0700
commit16572fd46e189d80c6be7d499e687fe129053a2c (patch)
tree69d053f8fecbf5eb9c558f6aec2c2b84c08220d3 /actionpack/lib/action_controller
parent95bd56e3cc028971059ac4ec0dfe3e29012ef35d (diff)
downloadrails-16572fd46e189d80c6be7d499e687fe129053a2c.tar.gz
rails-16572fd46e189d80c6be7d499e687fe129053a2c.tar.bz2
rails-16572fd46e189d80c6be7d499e687fe129053a2c.zip
read_ and write_fragment cache preserve html safety yet cache strings only
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/caching/fragments.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb
index bb5ff95a67..841e64ecaf 100644
--- a/actionpack/lib/action_controller/caching/fragments.rb
+++ b/actionpack/lib/action_controller/caching/fragments.rb
@@ -41,9 +41,7 @@ module ActionController #:nodoc:
else
pos = buffer.length
block.call
- content = buffer[pos..-1]
- content = content.as_str if content.respond_to?(:as_str)
- write_fragment(name, content, options)
+ write_fragment(name, buffer[pos..-1], options)
end
else
block.call
@@ -53,9 +51,10 @@ module ActionController #:nodoc:
# Writes <tt>content</tt> to the location signified by <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats)
def write_fragment(key, content, options = nil)
return content unless cache_configured?
- key = fragment_cache_key(key)
+ key = fragment_cache_key(key)
instrument_fragment_cache :write_fragment, key do
+ content = content.html_safe.as_str if content.respond_to?(:html_safe)
cache_store.write(key, content, options)
end
content
@@ -64,10 +63,11 @@ module ActionController #:nodoc:
# Reads a cached fragment from the location signified by <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats)
def read_fragment(key, options = nil)
return unless cache_configured?
- key = fragment_cache_key(key)
+ key = fragment_cache_key(key)
instrument_fragment_cache :read_fragment, key do
- cache_store.read(key, options)
+ result = cache_store.read(key, options)
+ result.respond_to?(:html_safe) ? result.html_safe : result
end
end