building a gallery layout

S

Sam Mayes

------=_Part_3443_2605247.1125509476090
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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

Sam

------=_Part_3443_2605247.1125509476090--
 
S

Sam Mayes

------=_Part_3859_14196189.1125513472542
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

html table ideally

Sam

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

------=_Part_3859_14196189.1125513472542--
 
J

Josh Charles

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
 
J

Josh Charles

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
 
S

Sam Mayes

------=_Part_4351_25053691.1125518573290
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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

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


</table>


=20
an array-less way to do it
=20
pictures[]
counter =3D 0
=20
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
=20
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
=20

------=_Part_4351_25053691.1125518573290--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top