【问题标题】:Rails array of images -- create links that will display the next/prev imagesRails 图像数组——创建显示下一个/上一个图像的链接
【发布时间】:2013-08-21 14:47:24
【问题描述】:

我仍然是 Rails 初学者,还有很多东西要学。

目前,我可以一次显示所有图像,没问题:

<!-- For the Thumbnail strip -->
<% @examples.each do |e| %>
    <ul class="example-grid"><%= e.description %></ul>
    <% if e.image.url != "/images/original/missing.png"  %>
        <p><%= image_tag e.image.url, size: "200x200" %></p>
    <% end %>
<% end %>

但我想首先显示@examples[0] 的图像,然后从那里有两个link_tobutton_to 路径来显示@example[current + 1]。类似的东西。

这是如何工作的?

感谢 SOF 社区!

【问题讨论】:

  • 这不是您最后一个标记块中的图像吗?
  • 是的,我知道——这就是我最终想要通过 Orbit 显示图像的方式:)。现在,我想知道如何通过链接点击图片(下一个和上一个)
  • 这个问题有点含糊。有太多的选择。简单的上一个/下一个链接意味着页面显示在单独的页面中。您可能希望通过 JS 滑块显示它们,并且有更多的预加载或不预加载选项,并且解决方案太多。简单来说,需要 View、Controller、分页 gem、JS lib 协同工作。

标签: ruby-on-rails-3 next orbit


【解决方案1】:

你可以使用Jquery Sliders,图片幻灯片插件 Image Slide show demo link

【讨论】:

    【解决方案2】:

    尝试引导轮播并像现在一样生成 html:

    http://getbootstrap.com/javascript/#carousel

    <div id="carousel-example-generic" class="carousel slide">
      <!-- Indicators -->
      <% @examples.each_with_index do |e, index| %>
      <ol class="carousel-indicators">
        <li data-target="#carousel-example-generic" data-slide-to="<%= index %>" class="<%= if e.primary ? "active" : "" %>></li>
      </ol>
      <% end %>
    
      <!-- Wrapper for slides -->
      <div class="carousel-inner">
      <% @examples.each do |e| %>
        <div class="item active">
    <% if e.image.url != "/images/original/missing.png"  %>
        <p><%= image_tag e.image.url, size: "200x200" %></p>
    <% end %>
          <div class="carousel-caption">
            ...
          </div>
        </div>
        ...
      </div>
    
      <!-- Controls -->
      <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
        <span class="icon-prev"></span>
      </a>
      <a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
        <span class="icon-next"></span>
      </a>
    </div>
    

    【讨论】:

    • 嘿@ovatsug25 你能为我分解这条线吗?我不明白发生了什么:
    • >
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签