Bootstrap Carousel首次使用渲染进行活动

时间:2014-07-03 14:45:43

标签: ruby-on-rails twitter-bootstrap

我正在使用渲染图像来显示我的图像。如何将第一个图像设置为Bootstrap Carousel有效?即<div class="item active">

房间/ show.html.erb

<!-- Wrapper for slides -->
<div class="carousel-inner">
    <%= render @images %>
</div>

图片/ _image.html.erb

<!-- Wrapper for slides -->
<div class="item">
  <%= image_tag image.image.normal.url %>
  <div class="carousel-caption">
    <%= image.name %>
  </div>
</div>

1 个答案:

答案 0 :(得分:3)

尝试:

<div class="carousel-inner">
  <% @images.each_with_index do |image, index| %>
    <%= render partial: "images/image", locals: {:index => index, :image => image} %>
  <% end %>
</div>

<!-- Wrapper for slides -->
<div class="item <%= 'active' if index == 0 %>">
  <%= image_tag image.image.normal.url %>
  <div class="carousel-caption">
    <%= image.name %>
  </div>
</div>