每一块都有?

时间:2009-07-22 14:43:07

标签: ruby-on-rails ruby haml

与标准周期一样:

- @goods.each do |good|
  ???

...组织这个(HAML):

.columns-wrapper
  .column First good
  .column Second good
  .column Third good

.columns-wrapper
  .column Fourth good
  .column Fifth good
  .column Sixth good

2 个答案:

答案 0 :(得分:4)

从您的示例中看,您看起来不想要多个块 - 您希望将一个数据集转换为多个数据集。我想你想要的是each_slice(3)

答案 1 :(得分:0)

require 'active_record'

@goods.in_groups_of 3, false do |goods|
  goods.each do |good|
    ...
  end
end