S
stephen O'D
I am totally new to rails, so sorry for the trivial question!
I have an object, gallery, that contains a list of images. I want to
display these images in a table with 4 columns and as many rows as it
takes, closing the final table row at the end.
What is the best way todo this?
I can do it (mostly, the final table row is still left open) using the
following template, but it seems a bit hackish in places:
<html>
<body>
<h1><%= @gallery.name -%></h1>
<table>
<%
i = 1
for img in @gallery.images
-%>
<%= if i == 1 || (i-1)%4 == 0
"<tr>"
else
""
end -%>
<td><img src='<%= img -%>'></td>
<%= "</tr>" if i%4 == 0 -%>
<%= i += 1
"" -%>
<% end -%>
</table>
</body>
</html>
Is there a better way?
I have an object, gallery, that contains a list of images. I want to
display these images in a table with 4 columns and as many rows as it
takes, closing the final table row at the end.
What is the best way todo this?
I can do it (mostly, the final table row is still left open) using the
following template, but it seems a bit hackish in places:
<html>
<body>
<h1><%= @gallery.name -%></h1>
<table>
<%
i = 1
for img in @gallery.images
-%>
<%= if i == 1 || (i-1)%4 == 0
"<tr>"
else
""
end -%>
<td><img src='<%= img -%>'></td>
<%= "</tr>" if i%4 == 0 -%>
<%= i += 1
"" -%>
<% end -%>
</table>
</body>
</html>
Is there a better way?