Passing Parameters to yield in Rails 3 (or is it possible?)
content-for, erb, ruby-on-rails-3, yield
Solution
I believe that what you were asking for is now possible:
# The template
<%= render layout: "my_layout" do |customer| %>
Hello <%= customer.name %>
<% end %>
# The layout
<html>
<%= yield Struct.new(:name).new("David") %>
</html>
From: http://api.rubyonrails.org/classes/ActionView/Helpers/RenderingHelper.html#method-i-_layout_for
Hopefully this helps someone else looking for the same solution.
Problem
I'm trying to create a dynamic content with `yield` and `content_for`. Basically i have bunch of layouts. And i dont want to create bunch of views for each layout. I want to render view parts when they are needed. For different parts of code it is ok. But i have problem with same parts with different content. in my `application.html.erb` ``` <%= yield %> <%= yield :name_section %> ``` And in my `show.html.erb` i have; ``` <% content_for :name_section do %> <b>Name:</b> <%= @post.name %> <% end %> ``` Here is the question; What if i want to multiple name_section with different contents. I mean; I want to put `:name_section` different places in my view with different contents. For ex; ``` <table> <tr> <td> <%= yield :name_section %> </td> </tr> <tr> <td> <%= yield :name_section %> </td> </tr> </table> ``` Any ideas? Thank you. Çağdaş