Search code examples
ruby-on-railsswiper.jsrails-activestorage

link_to rails_blob_path when clicked does not match the same image of image_tag inside the swiper slide div


In my view when i click the link_to (the slides i see side by side), does not match the slide. I am using active storage each home has many attached home_photos. This is ok. But my issue is i don't know how to implement this on my swiper slider. My images are showing on my slide side by side perfectly, but when i click a slide, it's supposed to pop-out, and it does, but it only shows one image, the first one from home_photos[0]. Please help.

    <div class="swiper-wrapper">
      <!-- Slides-->
      <% @home.home_photos.each do |photo| %>
        <div class="swiper-slide">
          <%= link_to rails_blob_path(@home.home_photos[0]), "data-toggle" => "gallery-top" do %>
            <%= image_tag photo, class: 'img-fluid' %>
          <% end %>
        </div>
      <% end %>
    </div>
    <div class="swiper-pagination swiper-pagination-white"></div>
    <div class="swiper-button-prev swiper-button-white"></div>
    <div class="swiper-button-next swiper-button-white"></div>

Solution

  • I think you have to change @home.home_photos[0] to photo in link_to:

    <%= link_to rails_blob_path(photo), "data-toggle" => "gallery-top" do %>