Wednesday, August 8, 2012

Make it easier to use partials with blocks in rails

The shorter version of render :partial is widely known and used. These are equivalent, but the second version is so much more succinct and readable. To use a partial with a yield in it, (what I call a "block partial"), you can use render :layout which a. doesn't read very well, (it's a partial, not a layout clearly), and b. can't be shortened nicely the way that render :partial can. So here is block_render: It lets you have nice neat render calls like this: This is a real-life example of a block partial I like to use. Those classes are bootstrap classes for making a nice drop down menu.

No comments: