Fixed regression for content_for #1820 [Stefan Kaes]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1911 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 b25f9af9
......@@ -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
......
......@@ -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 "<title>Putting stuff in the title!</title>\n\nGreat stuff!", @response.body
end
def test_update_element_with_capture
get :update_element_with_capture
......
<title><%= @title %></title>
<title><%= @title || @content_for_title %></title>
<%= @content_for_layout -%>
\ No newline at end of file
<% content_for :title do %>Putting stuff in the title!<% end %>
Great stuff!
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册