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

By manik January 11, 2008

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.

Share this:

Leave a comment

Your email address will not be published. Required fields are marked *