mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
layout_for works again with objects as specified in the documentation and Rails 2.3 [#5357 state:resolved]
This commit is contained in:
committed by
José Valim
parent
43b8722f4b
commit
1fbcd5f5fc
@@ -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
|
||||
|
||||
|
||||
1
actionpack/test/fixtures/layouts/_customers.erb
vendored
Normal file
1
actionpack/test/fixtures/layouts/_customers.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<title><%= yield Struct.new(:name).new("David") %></title>
|
||||
1
actionpack/test/fixtures/test/layout_render_object.erb
vendored
Normal file
1
actionpack/test/fixtures/test/layout_render_object.erb
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<%= render :layout => "layouts/customers" do |customer| %><%= customer.name %><% end %>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user