Building a gallery layout

Ive been trying to build a gallery layout for images. let say i have an
object of upto 25 images (results from an activerecord query) that I want to
display on a 5x5 grid but put blanks in the spaces should the result only
have say 13 images in the result. I need to make a table and have it do all
the table rows and columns based on the number f items returned in the ar
object. Does anyone have a quick exaple or a little pseudocode to help me
along. Obviously Im fairly new to ruby so be gentle please. thanks

Sam

Are you talking about an HTML table, or some other output/layout
mechanism?

html table ideally

Sam

···

On 8/31/05, Phrogz <gavin@refinery.com> wrote:

Are you talking about an HTML table, or some other output/layout
mechanism?

psuedo code from the top of my head

array[x,y]
pictures
counter = 0

for each array
   puts "<tr>"
   for each array[y]
      if ( pictures[ counter ] ) exists
         puts "<td>" + image code + "</td>"
      else
         puts "<td></td>"
      end
      counter ++
   end
   puts "</tr>"
end

Ok, so that would basically get you there. a better way might exist,
but that is my first instinct.

Hope that helps

Josh

···

On 8/31/05, Phrogz <gavin@refinery.com> wrote:

Are you talking about an HTML table, or some other output/layout
mechanism?

an array-less way to do it

pictures[]
counter = 0

5.times do
    puts "<tr>"
    5.times do
       if ( pictures[ counter ] ) exists
          puts "<td>" + image code + "</td>"
       else
          puts "<td></td>"
       end
       counter ++
    end
    puts "</tr>"
end

I think that is almost legal ruby code. I'm new to ruby, so I don't
know exactly. There is probably an even better way of doing this.
I'm really gray on ruby array handling

ok here is what i did may not be the most elegant but it works. thanks for
the help. any Ideas to make it better are welcome.

<table>
<tr>
<th>Company</th>
</tr>
<% counter = 0 %>
<% 5.times do %>
<tr>
<% 5.times do %>
<% if @systems[counter] %>
<td>
<table>
<tr>
<td><%= @systems[counter].company.name %></td>
<td><%= @systems[counter].model %></td>
<td><%= @systems[counter].sid %></td>
<td><%= @systems[counter].sm_img %></td>
</tr>
<% for price in @systems[counter].prices %>
<tr>
<td><%= price.price %></td>
<td><%= price.store_name %></td>
<td colspan="2"></td>
</tr>
<% end %>
</table>
</td>
<% else %>
<td></td>
<% end %>
<% counter+=1 %>
<% end %>
</tr>
<% end %>

</table>

···

On 8/31/05, Josh Charles <josh.charles@gmail.com> wrote:

an array-less way to do it

pictures
counter = 0

5.times do
puts "<tr>"
5.times do
if ( pictures[ counter ] ) exists
puts "<td>" + image code + "</td>"
else
puts "<td></td>"
end
counter ++
end
puts "</tr>"
end

I think that is almost legal ruby code. I'm new to ruby, so I don't
know exactly. There is probably an even better way of doing this.
I'm really gray on ruby array handling