Hello,
I apologize if this has been asked before.
I am interested in creating a helper for my view that generates a
grid-style table. Here’s what I have in application_helper.rb:
def print_grid_layout(items, table_class, num_columns)
print %Q{
\n}
rows = Array.new
# creates an array of arrays containing num_column items
num_columns.times do
rows << items.slice!(0…num_columns-1)
end
# for each row of items
rows.size.times do |i|
# figure out if we’re printing the top row, or subsequent rows.
if i.eql?(0) then row_class = “top” else row_class = “” end
print %Q{\s\s\n}
rows[i].each do |item|
print yield(item)
end
(num_columns - rows[i].size).times
print %Q{\s\s\s\s | \n}
end
print %Q{\s\s
\n}
end
The problem I am having is with the yield statement. In the template I
want my block to be the html for the cell, like so:
<% print_grid_layout(@product.product_variations, “variations”, 3) do
|product_variation| %>
<%=h product_variation.title %>
Catalog Num: <%=h product_variation.catalog_num %>
Price: $<%=h product_variation.price %>
|
<% end %>
It doesn’t seem to like the rhtml as a block.
Am I approaching the problem wrong? If so, what should I be doing
instead?