Some products have 0, 1, 2 or 3 images. How to display- bas

So this is the bassic html w/ eRB:

But what if the database has a pic2_url and a pic3_url (some will have
1 picture, some 2, and some 3)?

Obviously it shouldn’t display pic2_url and pic3_url if they aren’t
there.

And what about formatting: I’ve got a 400x400 box set for pictures –
if I have one picture, I’ll have it take up the whole table (supposing
all pictures are at least 400x400); if I have two, I’ll have it put
the pictures side by side (maybe breaking the table); if I have three,
I’ll split the table again. (and no pic_url at all leaves me with a
400px box that I might as well remove.) How do I solve this
problem?

Of course, I could just point to three “Image unavailable” images.

Thanks,
JD

So this is the bassic html w/ eRB:

But what if the database has a pic2_url and a pic3_url (some will have
1 picture, some 2, and some 3)?

<% if product.pic2_url %>

<% end %>

perhaps better to model the product pictures as a list instead of
hard-coding in the assumption that there will be at most 3 though. then
your erb code may become:

<% product.pic_urls.each do |url| %>

<% end %>

  • donald