Yield with Ruby on Rails
May 24
If you’ve worked with layouts in Rails then you’re most likely familiar with @content_for_layout, which basically substitutes the output of your view into the layout file. I was digging around earlier for some more information file and ran into an article talking about how <%= yield %> is preferred to <%= @content_for_layout %>. I can’t seem to dig up a link, but will update this post when I find it.
With that being said I’ve started using yield for my layout files, but am intrigued to know why it’s preferred. Maybe it’s the simple fact that yield seems to fall more in lines with Ruby’s intuitive language syntax. Speculation aside, it’s a simple change to make and you have nothing to lose in making it.
