Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4619

How to create a HAML6 helper that renders and returns at the same time?

$
0
0

I'm trying to design a helper for HAML, which would work like this:

%table- tabular(items) do |i|  %tr    %td      = i[:title]

I expect it to render the following HTML:

<table><tr><td>first</td></tr><tr><td>second</td></tr><tr><td>Total: 2</td></tr> <!-- This is not an item! --></table>

I'm trying this approach, but doesn't work:

def tabular(items)  total = 0  items.each do |i|    total += 1    yield i  end"<tr><td>Total: #{total}</td></tr>" # this line doesn't print :(end

Viewing all articles
Browse latest Browse all 4619

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>