Skip to content

Commit 20d6fdd

Browse files
committed
write_fragment returns content if caching is disabled [#846 state:resolved]
1 parent cd1a9ed commit 20d6fdd

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

actionpack/lib/action_controller/caching/fragments.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ module Caching
1010
# <%= render :partial => "topic", :collection => Topic.find(:all) %>
1111
# <% end %>
1212
#
13-
# This cache will bind to the name of the action that called it, so if this code was part of the view for the topics/list action, you would
14-
# be able to invalidate it using <tt>expire_fragment(:controller => "topics", :action => "list")</tt>.
15-
#
16-
# This default behavior is of limited use if you need to cache multiple fragments per action or if the action itself is cached using
13+
# This cache will bind to the name of the action that called it, so if this code was part of the view for the topics/list action, you would
14+
# be able to invalidate it using <tt>expire_fragment(:controller => "topics", :action => "list")</tt>.
15+
#
16+
# This default behavior is of limited use if you need to cache multiple fragments per action or if the action itself is cached using
1717
# <tt>caches_action</tt>, so we also have the option to qualify the name of the cached fragment with something like:
1818
#
1919
# <% cache(:action => "list", :action_suffix => "all_topics") do %>
2020
#
21-
# That would result in a name such as "/topics/list/all_topics", avoiding conflicts with the action cache and with any fragments that use a
22-
# different suffix. Note that the URL doesn't have to really exist or be callable - the url_for system is just used to generate unique
23-
# cache names that we can refer to when we need to expire the cache.
24-
#
21+
# That would result in a name such as "/topics/list/all_topics", avoiding conflicts with the action cache and with any fragments that use a
22+
# different suffix. Note that the URL doesn't have to really exist or be callable - the url_for system is just used to generate unique
23+
# cache names that we can refer to when we need to expire the cache.
24+
#
2525
# The expiration call for this example is:
26-
#
26+
#
2727
# expire_fragment(:controller => "topics", :action => "list", :action_suffix => "all_topics")
2828
module Fragments
29-
# Given a key (as described in <tt>expire_fragment</tt>), returns a key suitable for use in reading,
29+
# Given a key (as described in <tt>expire_fragment</tt>), returns a key suitable for use in reading,
3030
# writing, or expiring a cached fragment. If the key is a hash, the generated key is the return
3131
# value of url_for on that hash (without the protocol). All keys are prefixed with "views/" and uses
3232
# ActiveSupport::Cache.expand_cache_key for the expansion.
@@ -50,7 +50,7 @@ def fragment_for(buffer, name = {}, options = nil, &block) #:nodoc:
5050

5151
# Writes <tt>content</tt> to the location signified by <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats)
5252
def write_fragment(key, content, options = nil)
53-
return unless cache_configured?
53+
return content unless cache_configured?
5454

5555
key = fragment_cache_key(key)
5656

actionpack/test/controller/caching_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def test_write_fragment_with_caching_enabled
527527
def test_write_fragment_with_caching_disabled
528528
assert_nil @store.read('views/name')
529529
ActionController::Base.perform_caching = false
530-
assert_equal nil, @controller.write_fragment('name', 'value')
530+
assert_equal 'value', @controller.write_fragment('name', 'value')
531531
assert_nil @store.read('views/name')
532532
end
533533

0 commit comments

Comments
 (0)