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

**URL:** <https://www.ruby-forum.com/t/some-products-have-0-1-2-or-3-images-how-to-display-bas/90547>\
**Category:** Rails\
**Created:** [March 29, 2007, 9:13pm UTC](https://www.ruby-forum.com/t/some-products-have-0-1-2-or-3-images-how-to-display-bas/90547 "2007-03-29T21:13:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 29, 2007, 9:13pm UTC](https://www.ruby-forum.com/t/some-products-have-0-1-2-or-3-images-how-to-display-bas/90547/1 "2007-03-29T21:13:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 29, 2007, 9:49pm UTC](https://www.ruby-forum.com/t/some-products-have-0-1-2-or-3-images-how-to-display-bas/90547/2 "2007-03-29T21:49:41Z")

</div>

> 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
