Skip to content
Browse files

layout_for works again with objects as specified in the documentation…

… and Rails 2.3 [#5357 state:resolved]
  • Loading branch information...
1 parent f5c5cdd commit f08b58dd0c0ad860bb119bde94a46c6330ca1556 José Valim & Carlos Antonio da Silva committed with josevalim Aug 11, 2010
View
12 actionpack/lib/action_view/render/layouts.rb
@@ -47,11 +47,15 @@ module Layouts
# 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
View
1 actionpack/test/fixtures/layouts/_customers.erb
@@ -0,0 +1 @@
+<title><%= yield Struct.new(:name).new("David") %></title>
View
1 actionpack/test/fixtures/test/layout_render_object.erb
@@ -0,0 +1 @@
+<%= render :layout => "layouts/customers" do |customer| %><%= customer.name %><% end %>
View
5 actionpack/test/template/render_test.rb
@@ -252,6 +252,11 @@ def test_render_with_file_in_layout
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

0 comments on commit f08b58d

Please sign in to comment.
Something went wrong with that request. Please try again.