For Programmers: Free Programming Magazines  


Home > Archive > Ruby > August 2005 > building a gallery layout









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author building a gallery layout
Sam Mayes

2005-08-31, 7:00 pm

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

Phrogz

2005-08-31, 7:00 pm

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

Sam Mayes

2005-08-31, 7:00 pm

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


Josh Charles

2005-08-31, 7:00 pm

psuedo code from the top of my head

array[x,y]
pictures[]
counter =3D 0

for each array[x]
puts "<tr>"
for each array[x][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?
>=20
>=20
>



Josh Charles

2005-08-31, 7:00 pm

an array-less way to do it=20

pictures[]
counter =3D 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.=20
I'm really gray on ruby array handling


Sam Mayes

2005-08-31, 7:00 pm

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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com