-1

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> 
+0

도움이 될 경우 대답을 수락 할 수 있습니까? – Gabbar

+0

여기의 인덱스 변수는 nil입니다. 각 오브젝트 대신 반복적으로 each_with_index를 사용하십시오. –

답변

1

이유는 당신의 삼항 연산자 인 .... 내 클래스 내 삼항 연산자와 함께 할 수있는 뭔가가하지만 난 정확한 문제가 무엇인지 확실하지 않다 생각 이미지가있는 경우는 것보다, 그냥 문제를 해결 한

<div id="myCarousel" class="carousel slide" data-ride="carousel"> 
<!-- Indicators --> 
<ol class="carousel-indicators"> 
    <% @post.first(3).each_with_index do |image, index| %> <!--use each_with_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_with_index do |image, index| %> <!--use each_with_index --> 
    <div class="item <%= index == 0 ? 'active' : '' %>"> 
    <%#= link_to image_tag(image.image.url, class:"images") %> <!--use image_tag --> 
    <%=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> 

이 : index을 받고되지 않은 것은 당신이 대신 그래서 여기에 각

each_with_index으로 할 필요가 작업을 할 것은해야 할 올바른 방법입니다 지금 일해라. 추가 안내를 위해 알려주십시오.

+0

정확하게 문제가 발생했습니다. 대단히 감사합니다! –

관련 문제