title: Conditional tag wrapping in Rails / ERB
body: <p>What would be the most readable and/or concise way to write this in ERB? Writing my own method isn't preferable, as I would like to spread a cleaner solution for this to others in my company. </p>
  
  <pre><code>&lt;% @items.each do |item| %&gt;
    &lt;% if item.isolated? %&gt;
      &lt;div class="isolated"&gt;
    &lt;% end %&gt;
  
      &lt;%= item.name.pluralize %&gt; &lt;%# you can't win with indentation %&gt;
  
    &lt;% if item.isolated? %&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>== Update ==</p>
  
  <p>I used a more generic version of Gal's answer that is tag agnostic.</p>
  
  <pre><code>def conditional_wrapper(condition=true, options={}, &amp;block)
    options[:tag] ||= :div  
    if condition == true
      concat content_tag(options[:tag], capture(&amp;block), options.delete_if{|k,v| k == :tag})
    else
      concat capture(&amp;block)
    end
  end
  </code></pre>
  
  <p>== Usage</p>
  
  <pre><code>&lt;% @items.each do |item| %&gt;
    &lt;% conditional_wrapper(item.isolated?, :class =&gt; "isolated") do %&gt;
      &lt;%= item.name.pluralize %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>