Ruby on railsアプリケーションのPostgreSQLデータベースに保存された画像を使って、ブートストラップカルーセルに画像を読み込もうとしています。私はフロントエンドでERBを使用しています。何も以下のコードが現れると...データベースからブートストラップカルーセルにイメージを読み込むために、私の三項演算子がERBのクラスで動作しないのはなぜですか?
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<% @post.first(3).each do |image, index| %>
<li data-target="#myCarousel" data-slide-to="<%= index %>" class="<%= index == 0 ? 'active' : '' %>"></li>
<% end %>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<% @post.first(3).each do |image, index| %>
<div class="item <%= index == 0 ? 'active' : '' %>">
<%= link_to image_tag(image.image.url, class:"images") %>
<div class="">
<h3><%= index %></h3>
</div>
</div>
<% end %>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
あなたが役に立った場合、回答を受け入れることができますか? – Gabbar
ここではインデックス変数はゼロです。ポストオブジェクトを繰り返し処理するために、each_with_indexをそれぞれの代わりに使用してください。 –