diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 1877730c7e..d430121b04 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -82,9 +82,9 @@ module ActionView # NOTE: Beware that content_for is ignored in caches. So you shouldn't use it # for elements that are going to be fragment cached. def content_for(name, &block) - base = controller.instance_variable_get(instance_var_name(name)) || "" + base = instance_variable_get(instance_var_name(name)) || "" data = capture(&block) - controller.instance_variable_set(instance_var_name(name), base + data) + instance_variable_set(instance_var_name(name), base + data) data end diff --git a/actionpack/test/controller/capture_test.rb b/actionpack/test/controller/capture_test.rb index a48baaeda1..eab7865937 100644 --- a/actionpack/test/controller/capture_test.rb +++ b/actionpack/test/controller/capture_test.rb @@ -4,6 +4,10 @@ class CaptureController < ActionController::Base def self.controller_name; "test"; end def self.controller_path; "test"; end + def content_for + render :layout => "talk_from_action" + end + def rescue_action(e) raise end end @@ -27,6 +31,11 @@ class CaptureTest < Test::Unit::TestCase get :capturing assert_equal "Dreamy days", @response.body.strip end + + def test_content_for + get :content_for + assert_equal "