在代码中:
<% @offers.each do |offer|%>
<%= offer.percentageOff%> <b>% OFF on order of</b>
<%= image_tag('1407951522',:size=>'10x10',:alt=>'Rs.')%>
<%= offer.amountforDiscount%>
<%= button_to 'Delete',{:action=>'destroy',:id=>offer.id},class: "" %>
<% end %>
我是铁杆新手。我想在编号列表中显示所有商品,我无法使用数据库表,因为id
不符合要求。例如:
订购Rs.2000
订购Rs.1000
我如何实现这一目标?
答案 0 :(得分:7)
最简单的方法,如果你不想使用each_with_index
那么你可以定义变量@count=0
并显示,因为循环发生它将增加1
<% @count = 0 %>
<% @offers.each do |offer|%>
<%= @count += 1 %> #I guess you want this to show Sr.No
...... # your code
<% end %>
<% @offers.each_with_index do |offer, index|%>
<%= index + 1 %> # index starts from 0, so added 1 to start numbering from 1
...... # your code
<% end %>