我有一個項目列表,我在每個視圖中循環顯示。這完全沒問題。然而,我想要得到每個項目的數量,每個項目的增量都隨着每個循環而增加(i = 0,我知道鑽取i ++)。在視圖軌中計數
現在,我該如何在Rails中做到這一點?這是我現在得到的:
<% i = 0 %>
<% @trip.triplocations.each do |tl| %>
<article id="<%= dom_id(tl) %>">
<strong> <%= tl.title %> </strong>
<p>
<%= tl.description %>
</p>
</article>
<% end %>
這肯定奏效!然而;有可能在1開始我?因爲我想用它作爲視覺編號。 – CaptainCarl
你可以像這樣'<%= i+1 %>'增加1。這應該工作,但更多的信息看看[這裏](http://stackoverflow.com/questions/5646390/ruby-each-with-index-offset)。 –
夠公平,謝謝! – CaptainCarl