Search code examples
javascriptruby-on-railsdatabaseimagecycle

Blank image at start of js slideshow - Ruby on Rails


I'm fairly new so please forgive any lack of knowledge I may have.

I'm using the cycle2 plugin on a project and I've made one slideshow on my index page work fine, there's no issues with it at all as its pulling images from the net.

However I want to do a slideshow on the show page, so that for each product it pulls the product image from the database. I've made it so it does, however when doing so the first image of the slideshow is always empty and continuously trying to load until it changes to the picture from the database.

I'm pretty sure its something in the img src that I'm doing wrong as its getting the image, just getting a blank slide too, any help would be greatly appreciated!

The code so far is;

        <div id="slideshow">

                        <div class="cycle-slideshow" 
                            data-cycle-fx=scrollHorz
                            data-cycle-timeout=4000
                            style="z-index:-1;"
                            data-cycle-prev="#prev"
                            data-cycle-next="#next"
                            >
                            <!-- empty element for pager links -->
                            <div class="cycle-pager"></div>
                                <!-- empty element for overlay -->
                            <img src =  <%= link_to image_tag @product.image_url %>>
                        <!-- prev/next links -->
                        <div id=outside>
                        <span id=prev><a href="#" class="button1">?</a></span>
                        <span id=next><a href="#" class="button1">? </a></span>

                </div>
        </div>

Thanks, Ben


Solution

  • Use this: <%= image_tag(product.image_url) %>. That's what I used to make mine work.