# Lightbox :/

**URL:** <https://www.ruby-forum.com/t/lightbox/181929>\
**Category:** Rails\
**Created:** [January 20, 2010, 10:53am UTC](https://www.ruby-forum.com/t/lightbox/181929 "2010-01-20T10:53:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [January 20, 2010, 10:53am UTC](https://www.ruby-forum.com/t/lightbox/181929/1 "2010-01-20T10:53:54Z")

</div>

I’m using a Lightbox on a local site. I’ve built a Gallery that allows a  
user to upload images in a secure admin area. I have the Lightbox  
working a treat but I do have one small issue - I’ve grouped the images  
so the user can scroll through them when they open the Lightbox.

Code:

\<%= link\_to (scale\_image\_tag gallery.picture1, :width =\> 100, :height =\> 100, :rel =\> "lightbox[@gallery]", :alt =\> gallery.name), gallery.picture1.url, :rel =\> "lightbox[@gallery]", :title =\> gallery.name %\>  
\<%= link\_to gallery.name, gallery.picture1.url, :rel =\> "lightbox[@gallery]", :title =\> gallery.name %\>

When the Lightbox opens, the image counter at the bottom isn’t correct  
and I can’t seem to find the correct way to address this issue, please  
help.

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [January 20, 2010, 12:14pm UTC](https://www.ruby-forum.com/t/lightbox/181929/2 "2010-01-20T12:14:36Z")

</div>

Problem solved but it has raised another question:

The Lightbox is displayed on an index page that, on refresh, generates a  
random image. To do this, I simply added a new model method:

def self.random  
self.find(:first, :conditions =\> “display=1 AND picture1\_id IS NOT  
NULL”, :order =\> “RAND()”)  
end

Next, I added the code to the view by defining: \<% gallery =  
Gallery.random %\>

Obviously, this removes the scrolling capability of the Lightbox as the  
group only consists of one instance: the randomly generated image. My  
question is: How can I display one random image but have the ability to  
scroll through images when in the Lightbox?
