Rails-Tip : Use Capture to wrap a part of View in a variable

The view helper method capture provides this functionality to wrap a section of the view template in a variable and can be used multiple times in the view.

Usage :

Advantage:

If its needed to render a section of template code, we usually go with partials. Capture is specifically useful when partial is only going to be used in just one view template. As there will be this variable available throughout the template, we can use it as many times as needed instead of partial.

Related posts:

  1. Rails Caching And JavaScript Techniques Cross posted from darthsid While implementing caching in a recent...

Related posts brought to you by Yet Another Related Posts Plugin.

del.icio.us Digg it reddit Yahoo MyWeb
blog comments powered by Disqus