aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_view/render/layouts.rb12
-rw-r--r--actionpack/test/fixtures/layouts/_customers.erb1
-rw-r--r--actionpack/test/fixtures/test/layout_render_object.erb1
-rw-r--r--actionpack/test/template/render_test.rb5
4 files changed, 15 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/render/layouts.rb b/actionpack/lib/action_view/render/layouts.rb
index a474783a20..8882acca31 100644
--- a/actionpack/lib/action_view/render/layouts.rb
+++ b/actionpack/lib/action_view/render/layouts.rb
@@ -47,11 +47,15 @@ module ActionView
# Hello David
# </html>
#
- def _layout_for(name = nil, &block) #:nodoc:
- if !block || name
- @_content_for[name || :layout].html_safe
+ def _layout_for(*args, &block) #:nodoc:
+ name = args.first
+
+ if name.is_a?(Symbol)
+ @_content_for[name].html_safe
+ elsif block
+ capture(*args, &block)
else
- capture(&block)
+ @_content_for[:layout].html_safe
end
end
diff --git a/actionpack/test/fixtures/layouts/_customers.erb b/actionpack/test/fixtures/layouts/_customers.erb
new file mode 100644
index 0000000000..ae63f13cd3
--- /dev/null
+++ b/actionpack/test/fixtures/layouts/_customers.erb
@@ -0,0 +1 @@
+<title><%= yield Struct.new(:name).new("David") %></title> \ No newline at end of file
diff --git a/actionpack/test/fixtures/test/layout_render_object.erb b/actionpack/test/fixtures/test/layout_render_object.erb
new file mode 100644
index 0000000000..acc4453c08
--- /dev/null
+++ b/actionpack/test/fixtures/test/layout_render_object.erb
@@ -0,0 +1 @@
+<%= render :layout => "layouts/customers" do |customer| %><%= customer.name %><% end %> \ No newline at end of file
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 059dcedad8..60d4d9f4a7 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -252,6 +252,11 @@ module RenderTestCases
assert_equal %(\n<title>title</title>\n\n),
@view.render(:file => "test/layout_render_file.erb")
end
+
+ def test_render_layout_with_object
+ assert_equal %(<title>David</title>),
+ @view.render(:file => "test/layout_render_object.erb")
+ end
end
class CachedViewRenderTest < ActiveSupport::TestCase