This project is archived and is in readonly mode.
Pass block args for render :layout
-
Ryan Bates
Also, you could get fancy and yield multiple times for different sections of the layout. For example.
<!-- _comment.html.erb --> before <%= yield comment, :time %> middle <%= yield comment, :extra %> after <!-- some view --> <% render :layout => @comments do |comment, section| %> <% case section when :time %> <%= comment.created_at %> <% when :extra %> some extra content <% end %> <% end %> <!-- output --> before 2008-01-01 00:00:00 (whatever time the comment was created) middle some extra content afterThis way you can easily and dynamically customize various parts of the layout/partial when rendering it.
-
DHH
I like this, but we need to get some documentation on the method along with the patch.
-
Ryan Bates
thanks, documentation is planned, just wanted to nail down the functionality first.
-
Ryan Bates
Here's an updated patch with docs.
-
josh
If @proc_for_layout is private, lets prefix it with an underscore. I started doing that with a few other instance variables that are available in the view scope.
The execute method was always a bad smell on Base. I wonder if we could easily move that over into the Renderable#render method. (This isn't exactly related to your patch buts its always nice to cleanup these little things when we spot them)
-
Ryan Bates
Here's an updated patch with the underscore prefix. I'm not sure what's involved in moving the execute method over to renderable, so I'll leave that to you. :)
-
Repository
- State changed from new to resolved
(from [38c7d73e73d569211c4dfadf96fc295a925b7c9c]) pass yielded arguments to block for ActionView::Base#render with :layout [#847 Pass block args for render :layout state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
-
josh
- Assigned user set to josh
- Milestone cleared.
- State changed from resolved to open
Someone found a 2.1 regression bug due to this commit.
The block arguments passed in shadow any existing @content_for_*.
# index.erb <% content_for :column do %>column<% end %> <% render :layout => 'layouts/column' do %>content<% end %> # layouts/column.erb <div id="column"><%= yield :column %></div> <div id="content"><%= yield %></div>The "yield :column" always returns what is in the block "content" first and it never looks up @content_for_column.
-
Ryan Bates
This should be fixable by checking for the existence of the @content_for_* instance variable before executing the block. I'll try to write up a patch later today.
-
josh
I was playing with that idea but it got real hairy real fast. Good Luck :)
-
Ryan Bates
Here's a patch which fixes this problem by checking for the existence of the content_for ivar before executing the block. Your tests are included.
-
Brendon
I'm experiencing a bug when trying to yield a Date object. It results in:
@content_for_2009-03-29' is not allowed as an instance variable name -
Ryan Bigg
Automatic cleanup of spam.
