Grid making helper in view


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{

rows =
# creates an array of arrays containing num_column items
num_columns.times do
rows << items.slice!(0…num_columns-1)
# 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)
(num_columns - rows[i].size).times
print %Q{\s\s\s\s\n}
print %Q{\s\s\n}

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| %>

<% 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


<%=h product_variation.title %>

Catalog Num: <%=h product_variation.catalog_num %>

Price: $<%=h product_variation.price %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs