Can someone explain the difference between \"<%= render %>
\" and \"<%= yield %>
with <% content_for :partial do %>
/
When your controller method exits, it renders the associated file. So the edit controller renders edit.html.erb. It uses the specified layout or application.html.erb if none is specified.
Within your layout file, when you call yield
it will fill in the information from your render. If you call yield
with a parameter, it will look for a content_for
section in your render file matching that parameter. I'm not completely sure, but I don't think you can call yield
from outside of your layout file, and I don't think it will fill in any information except that found in your render file.
Anywhere in your layout file or your rendered file, you can render a partial by calling render
with the partial name minus the underscore.
I hope that helps.
Edit to answer question in comment:
yield
and render
perform similar functions however yield
only looks in the render file whereas render
specifies which file to render. Also, render
outputs the entire file, but yield
with a parameter can output just a subsection of the file.