Note that there are some explanatory texts on larger screens.

plurals
  1. PORails creating a thumbnail gallery in my view
    text
    copied!<p>I currently have an Array that contains some URL's to images. </p> <p><code>@images = [ "http://site/images/01.jpg", "http://site/images/02.jpg" ]</code></p> <p><strong>Total 18 images</strong></p> <p>I would like to take this array and create a thumbnail gallery where <strong>the gallery is 3 columns across in my view</strong>. The HTML out put would be</p> <p><code> &lt;table&gt;<br> &lt;tr&gt;<br> &lt;td&gt;&lt;img src="http://site/images/01.jpg"&gt;&lt;/td&gt;<br> &lt;td&gt;&lt;img src="http://site/images/02.jpg"&gt;&lt;/td&gt;<br> &lt;td&gt;&lt;img src="http://site/images/03.jpg"&gt;&lt;/td&gt;<br> &lt;/tr&gt;<br> &lt;tr&gt;<br> &lt;td&gt;&lt;img src="http://site/images/04.jpg"&gt;&lt;/td&gt;<br> &lt;td&gt;&lt;img src="http://site/images/05.jpg"&gt;&lt;/td&gt;<br> &lt;td&gt;&lt;img src="http://site/images/06.jpg"&gt;&lt;/td&gt;<br> &lt;/tr&gt;<br> &lt;/table&gt;</code></p> <p>My <strong>current implementation</strong> gets me a one column table</p> <p><code>&lt;table&gt;</code><br> <code>&lt;tr&gt;</code><br> <code>&lt;% @images.each do | image | %&gt;</code><br> <code>&lt;td&gt;&lt;%= image_tag(image)%&gt;&lt;/td&gt;&lt;br&gt;</code><br> <code>&lt;% end %&gt;</code><br> <code>&lt;/tr&gt;</code><br> <code>&lt;/table&gt;</code> </p> <p>In the future I might want it to be 6 columns instead of 3 columns. I'm looking for a way to do this in a clean and flexible way.</p> <p>I was looking at the <strong>Ruby documentation</strong> and I saw this <strong>Class Range (rng.step method)</strong> <a href="http://www.ruby-doc.org/core/classes/Range.html" rel="nofollow">http://www.ruby-doc.org/core/classes/Range.html</a></p> <p>Not sure if this Range class <strong>step method</strong> can solve the problem but the example it provides is interesting.</p> <p>Any thoughts, I'm still learning and maybe I'm over thinking this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload