Ruby on rails 查看将列表拆分为两列的帮助器

Ruby on rails 查看将列表拆分为两列的帮助器,ruby-on-rails,Ruby On Rails,我有个小问题 我正在haml视图中呈现定义列表。这是代码 .col - @product.data.each do |features_group_id, features_group| .data-group %h3= features_group["name"] %dl - features_group['features'].each do |id, hash|

我有个小问题

我正在haml视图中呈现定义列表。这是代码

    .col
      - @product.data.each do |features_group_id, features_group|
        .data-group
          %h3= features_group["name"]
          %dl
            - features_group['features'].each do |id, hash|
              - if @product.product_category.show_feature_ids.include?(id)
                %span.data-wrap
                  %dt
                    = hash['name']
                  %dd
                    = hash['value']
我必须把这份名单分成两列

我必须取product.data.count/2并在两列中显示这两个块

    .col
      - @product.data_batch1.each do |features_group_id, features_group|
        .data-group
          %h3= features_group["name"]
          %dl
            - features_group['features'].each do |id, hash|
              - if @product.product_category.show_feature_ids.include?(id)
                %span.data-wrap
                  %dt
                    = hash['name']
                  %dd
                    = hash['value']
    .col
      - @product.data_batch2.each do |features_group_id, features_group|
        .data-group
          %h3= features_group["name"]
          %dl
            - features_group['features'].each do |id, hash|
              - if @product.product_category.show_feature_ids.include?(id)
                %span.data-wrap
                  %dt
                    = hash['name']
                  %dd
                    = hash['value']
有什么简单的解决方案可以做到这一点吗?

您可以使用,因为
@product.data
是或充当
数组

从您的代码:

    - @product.data.in_groups_of(2, false).each do |group|
      .col
        - group.each do |features_group_id, features_group|
          .data-group
            %h3= features_group["name"]
            %dl
              - features_group['features'].each do |id, hash|
                - if @product.product_category.show_feature_ids.include?(id)
                  %span.data-wrap
                    %dt
                      = hash['name']
                    %dd
                      = hash['value']

甚至在这上面也有!:-)

如何分割批次。是上半部分还是下半部分?@emaillenin是的,如果product.data.count是18,则分两批,共9批,如果是13->7+6