This project is archived and is in readonly mode.
render(:inline) in a layout before yield replaces original content
Reported by Travis | June 6th, 2010 @ 04:52 PM | in 3.0.2
The issue I'm seeing is that if you call render(:inline => "some text") in the layout before yielding to the main content for the page, the content of the yield will replace the original content of the page.
Perhaps this is the intended behavior and I just don't understand. I haven't delved into the source yet to see why this is happening, or if using render :inline in a layout is in fact incorrect usage.
Nor have put together tests or a demo to exhibit it, but it's fairly simple to reproduce.
Given a fresh project with a controller 'test' and an #index
action.
rails g controller test index
In config/routes.rb
root :to => "test#index"
In app/views/layouts/application.html.erb
<%= render :inline => "layout inline 1" %>
<%= yield %>
<%= render :inline => "layout inline 2" %>
If you start up the server and hit the home page you'll
see:
layout inline 1
layout inline 1
layout inline 2
The content in index.html.erb has been replaced by the inline render prior. This does not happen in Rails 2.
Comments and changes to this ticket
-
Rohit Arondekar June 11th, 2010 @ 10:49 AM
- Tag set to rails 3, actionview, render
- Assigned user set to José Valim
Confirmed on Rails master, Ruby 1.9.2-head.
According to the edge api docs => http://edgeapi.rubyonrails.org/classes/ActionView/Rendering.html#M0...
:inline - Renders an inline template similar to how it‘s done in the controller.
-
José Valim June 11th, 2010 @ 10:52 AM
- Milestone cleared.
-
Neeraj Singh June 11th, 2010 @ 06:45 PM
- Tag changed from rails 3, actionview, render to rails 3, actionview, patch, render
Attached is patch with test.
-
Rohit Arondekar June 12th, 2010 @ 02:20 AM
+1 applies cleanly, tests pass on the following Rubies:
- ruby 1.8.7 (2009-06-12 patchlevel 174)
- ruby 1.9.2dev (2010-06-06 revision 28184)
-
José Valim June 12th, 2010 @ 06:44 AM
The tests may pass, but it's not the correct fix because we should not use the identifier for the purpose above and it's a special check for a given template type. I will discuss with Yehuda a bit more and follow up soon, but a more acceptable solution would be to only set the layout if a layout object exists:
@_content_for[:layout] = content if layout (only set the content for layout if there is a layout)
Neeraj, could you try this solution and see if all tests still pass?
-
Neeraj Singh June 13th, 2010 @ 04:04 AM
Attached is modified patch (and same test) based on feedback by José .
-
Rohit Arondekar June 13th, 2010 @ 04:55 AM
Applies cleanly and the tests pass on 1.8.7 and 1.9.2-head.
-
Repository June 13th, 2010 @ 12:56 PM
- State changed from new to resolved
(from [e574ca920d315158a4af5c906b23ea0082c5690f]) render(:inline) in a layout before yield replaces original content
[#4777 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/e574ca920d315158a4af5c906b23ea... -
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to High
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 4777 render(:inline) in a layout before yield replaces original content [#4777 state:resolved]