So, I’m trying to understand the content_for
example in the Output Helpers section, but I’m unable to figure out how to make it work. Specifically, there are some questions that are arising that the documentation isn’t answering, nor did I find anything in the forum to help guide me.
-
In the
content_for
example, does the declaration of<% content_for :assets do %>
live in just any template file? How does<%= yield_content :assets %>
know where to find the captured content? -
I have the following block of code in my index.html.erb:
` <% content_for :puppies do%>-
<% 3.times do |num| %>
- Puppy <%= num %> <% end %>
<% end %>
I see no
- ` stating “Puppy 1” “Puppy 2” “Puppy 3” rendered on the page at all. Does content_for hide the display of the contents within its block?
-
With the above example I have the following in the body of layouts/test.erb:
<%= yield_content :puppies %>
But the ul of puppies is not output there either. -
Is there a use case that someone could provide to better explain why someone would use this method?
-
Additionally, if someone could provide an example of how to use
capture_html
andconcat_content
(and their appropriate yields), and perhaps a short description of when people could use them.
Any help at all would be appreciated! If I’m able to understand when and how to use these, I’m more than happy to submit a pull request for the documentation.