I see this sometimes in a partial erb template:
<%= yield :someval %>
Other times there is no yield at all.
What’s the advantage of calling yield in a partial?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I have used it in the past if I have a partial that could be called from different pages that might need some contextual content from the page.
A use case that I had was for a menu. I had my stock menu items, but then I had a
yield(:menu), so that what the user loaded the administration page, I could add menu items from the page instead of writing a condition statement in the partial itself.This is some pseudo code:
_menu.haml
users.haml
roles.haml
As opposed to:
While both are functional (if it was real code), I prefer the first method. The second can spiral out of control and get pretty ugly pretty fast. It is a matter of preference though.