Arnaud J. wrote:
def hidden_div_if(condition, attributes = {}, &block) if condition attributes["style" ] = "display: none" end content_tag("div" , attributes, &block)
Look inside the content_tag source. Is it using capture? That takes a &block, and it must treat the block specially to bind to its eRB context.
<% hidden_div_if(@cart.items.empty?, :id => "cart" ) do %> <%= render(:partial => "cart" , :object => @cart) %> <% end %>
eRB starts by converting <%%> marks into a mishmash of strings and eRB method calls. A simple do-end block would evaluate in the wrong context, so capture() provides the correct context. And you can't just yield into it.
Someone may correct me, but that appears to apply to your first example, not your second. You yielded without a capture, so you yielded in the wrong context.