How are Rails ERB's layouts implemented? I tried looking through the source, but I couldn't determine where/how they work.
I am specifically interested in how the yield part works, how erb includes the rendered view in a template.
The reason I need it, is so that I can use it for code generation, non Rails, non HTML related ( and because it would be interesting to know how they work )
Rails renders inside out, so it will render the show.html.erb first and store that in a variable. It will then render the layout
inside the layout you see
<%= yield %>
which will get replaced with the shot.html.erb text
This is also how the following work. In your page, you might say:
<% content_for(:footer) do %>
...
<% end %>
And then layer in your layout you can:
<%= yield(:footer) %>
I like to think of it as just an inside-out setting of variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With