diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb index 1877730c7e8835a42374d1292d35a5f399164f51..d430121b040dabeebcd5dfa31a9b51ae70e4d86c 100644 --- a/actionpack/lib/action_view/helpers/capture_helper.rb +++ b/actionpack/lib/action_view/helpers/capture_helper.rb @@ -82,9 +82,9 @@ def capture(*args, &block) # 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 a48baaeda1f05a354b22683be2f98e444b622b70..eab78659374c4714c82fd9c05f14ebb6db5f7dfe 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 @@ def test_simple_capture get :capturing assert_equal "Dreamy days", @response.body.strip end + + def test_content_for + get :content_for + assert_equal "Putting stuff in the title!\n\nGreat stuff!", @response.body + end def test_update_element_with_capture get :update_element_with_capture diff --git a/actionpack/test/fixtures/layouts/talk_from_action.rhtml b/actionpack/test/fixtures/layouts/talk_from_action.rhtml index 215dfd27ac359bb1e8b5d33dc194436d6ae7573c..187aab07a270d58fb3eaf067a125a011ba575d35 100644 --- a/actionpack/test/fixtures/layouts/talk_from_action.rhtml +++ b/actionpack/test/fixtures/layouts/talk_from_action.rhtml @@ -1,2 +1,2 @@ -<%= @title %> +<%= @title || @content_for_title %> <%= @content_for_layout -%> \ No newline at end of file diff --git a/actionpack/test/fixtures/test/content_for.rhtml b/actionpack/test/fixtures/test/content_for.rhtml new file mode 100644 index 0000000000000000000000000000000000000000..0e47ca8c3d07ff98f32822071db097c2a77a16f4 --- /dev/null +++ b/actionpack/test/fixtures/test/content_for.rhtml @@ -0,0 +1,2 @@ +<% content_for :title do %>Putting stuff in the title!<% end %> +Great stuff! \ No newline at end of file