Ruby on rails erb块不循环
我正在尝试使用这个erb块为webstore生成结果,我希望每行有4个图像,但现在它每行只生成一个图像。如有任何建议,将不胜感激Ruby on rails erb块不循环,ruby-on-rails,iterator,erb,Ruby On Rails,Iterator,Erb,我正在尝试使用这个erb块为webstore生成结果,我希望每行有4个图像,但现在它每行只生成一个图像。如有任何建议,将不胜感激 <% n = 4 %> <% @products.each do |product| %> <div class="row-fluid"> <% if (n%4 == 0) %> <% end %> <div class="span3"> <%= link_to image_
<% n = 4 %>
<% @products.each do |product| %>
<div class="row-fluid">
<% if (n%4 == 0) %>
<% end %>
<div class="span3">
<%= link_to image_tag(product.images.order(:placement).first.image.url(:medium)), product if product.images.present? %>
<p class="text-center"><%= link_to product.name, product %></p>
</div>
<% if (n%4 == 3) %>
<% end %>
<% n += 1 %>
</div>
<% end %>
Ruby将使用以下方法将其分为四组:
太棒了,我不知道。谢谢
<% @products.each_slice(4) do |row| %>
<div class="row-fluid">
<% row.each do |product| %>
<div class="span3">
<%= link_to image_tag(product.images.order(:placement).first.image.url(:medium)), product if product.images.present? %>
<p class="text-center"><%= link_to product.name, product %></p>
</div>
<% end %>
</div>
<% end %>