Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css RubyonRails通过索引进行迭代_Css_Ruby On Rails_Ruby - Fatal编程技术网

Css RubyonRails通过索引进行迭代

Css RubyonRails通过索引进行迭代,css,ruby-on-rails,ruby,Css,Ruby On Rails,Ruby,以下是我向用户显示图像的视图: <div id="lightgallery" class="col-md-8 detailpage-images-gallery" > <% if @product.product_attachments.present? &&@product.product_attachments.count > 0 %> <% @product.product_attachments.each_with_index d

以下是我向用户显示图像的视图:

<div id="lightgallery" class="col-md-8 detailpage-images-gallery" >
 <% if @product.product_attachments.present? &&@product.product_attachments.count > 0 %>
  <% @product.product_attachments.each_with_index do |attachment, index| %>

    <% if index == 0 %>
      <div class="col-sm-6 col-md-6 topleftimg <%='hidden-xs' if index !=  @product.product_attachments.count - 1 %>" data-responsive="<%= attachment.attachment.large.url %>" data-src="<%= attachment.attachment.large.url %>" data-sub-html="<%= @product.highlight %>">
        <a class="photo-grid-photo photo-trigger" style="background-image:url('<%= attachment.attachment.square.url %>');" href="#" title="Photo 2 of 6" data-index="1" data-prevent-default="true">
        <img src="<%= attachment.attachment.square.url %>" class="hide" alt="Photo 2 of 6"></a>
      </div>

    <% elsif index == 1 %>
     <div class="col-sm-6 col-md-6 toprightimg <%='hidden-xs' if index != @product.product_attachments.count - 1 %>" data-responsive="<%= attachment.attachment.large.url %>" data-src="<%= attachment.attachment.large.url %>" data-sub-html="<%= @product.highlight %>">                
      <a href=""><img src="<%= attachment.attachment.small.url %>" class="img-responsive"></a>
    </div>
    <% end %>                       
  <% end %>
 <% end %>
</div>

0 %>

在我看来,我限制显示最多5个图像,但一旦用户单击,他们可以看到5个以上的图像。我如何迭代
索引
,而不是使用
获取所有图像?如何修改css,以便在出现5个以上的图像时,可以将
style=“display:none”
附加到
div
的其余部分?谢谢

你指的是分页吗?或者简单地说如何遍历5个元素?@maxpleaner简单地遍历索引。使用js是一个选项吗?如果是这样,您可以在按钮上设置一个点击功能来更改css。@margo,不能在这里使用js,因为
lightgallery
将使用索引中的
div
弹出一个包含所有小拇指的图库演示文稿,表示:
&&&product.product\u attachments.count
完全没有意义,并且显示出对ruby中布尔值的组织方式理解不足
@product.product\u attachments.count
的计算结果永远不会为
if@product.product\u attachments.present?
也完全没有意义,因为
product\u attachments
是一种关系,不能
nil