我有這樣的代碼:管理優化@視圖
<% if @photos.blank? %>
No Pic
<% else %>
<center>
<table>
<tr>
<% @photos.each do |c| %>
<td>
<%= image_tag(url_for({:action => 'image', :id => c.id}),:width =>'20%', :height =>'20%') %><br>
<%= link_to "lihat" , {:action => 'show2', :id => c.id} -%>
<% if logged_in? %>
<small> <%= link_to 'Edit', {:action => "edit2", :id => c.id } %></small>
<small> <%= link_to 'Delete', {:action => "delete2", :id => c.id }, :confirm => "apakah anda yakin mau mengapus berita ini?" %></small>
<% end %>
</td>
<% end %>
</tr>
</table>
</center>
<% end %>
我想打印我的圖片「如果列= 5」全自動添加每行
或5圖像 輸出: [圖像] [圖像] [圖片] [圖片] [圖片]
我該怎麼處理我的代碼?請幫我
方式更好的答案比我想(用each_with_index和MOD 5)。很乾淨! – mixonic 2009-08-06 13:20:45
仍然錯誤!如果我使用each_with_index作爲例子,我該如何輸入? – 2009-08-06 19:06:10
你能更具體地瞭解這個錯誤嗎?它與Array#in_groups_of沒有直接關係,然後是Array#each_with_index(我提到的'兩種方法'中的第二個;))可能無法幫助你! – 2009-08-07 02:01:03