Forum: Ruby on Rails Grid making helper in view

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Nithin R. (Guest)
on 2006-03-15 03:46
(Received via mailing list)

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{<table class='#{table_class}' cellpadding='0'
    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<tr class="#{row_class}">\n}
      rows[i].each do |item|
        print yield(item)
      (num_columns - rows[i].size).times
        print %Q{\s\s\s\s<td class="blank">&nbsp;</td>\n}
      print %Q{\s\s</tr>\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| %>
    <td class="normal" id="ProductVariation_<%=
        <strong><%=h product_variation.title %></strong> <br />
        Catalog Num: <%=h product_variation.catalog_num %> <br />
        Price: $<%=h product_variation.price %> <br />
<% 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
This topic is locked and can not be replied to.