ruby-on-railsbxslider

How to show two images in one slide


Am using bxslider in my rails app it works fine. It shows one image per slide but i want is to show two images per slide.

<ul class="bxslider">
  <% @highlights.each do |highlight| %>
  <% if highlight.area == current_or_guest_user.search_area or highlight.state == current_or_guest_user.search_state or highlight.city == current_or_guest_user.search_city %>
  <li><%= image_tag highlight.image, :class => "dali" %></li>
  <% end %>
  <% end %>
</ul>

if i replicate the image_tag it does show two images in one slide but the same image.


Solution

  • You can get the records in pairs. Try this:

    <ul class="bxslider">
      <% @highlights.each_cons(2) do |highlight1, highlight2| %>
        <% if condition %>
          <li class="row">
            <%= image_tag highlight1.image, :class => "dali col-xs-6" %>
            <%= image_tag highlight2.image, :class => "dali col-xs-6" %>
          </li>
        <% end %>
      <% end %>
    </ul>