如何在不复制 Active Admin 中的 'parent' 列条目的情况下添加第二列 'children'?

How do you add a second column of 'children' without duplicating the 'parent' column entry in Active Admin?

这个 table、Raw Table with correct output 是我正在寻找的结果,但是我如何将这个代码块转换成任何 Active Admin /app/admin/postal_code.rb 索引视图需要正确输出 table。

目前这个块是部分渲染的,/app/views/admin/postalcode/_showtable。html.erb

<h1>Postal Code per Region</h1>
<table>
<tr>
    <th>Region</th>
    <th>Postal Code</th>
</tr>
<% @region.each do |region| %>
<tr>
    <td><%= region.name %></td>
    <td>
        <table>
            <% list = @postalcode.where("region_id=#{region.id}") %>
            <% list.each do |l| %>
            <tr>
                <td width="5%">
                    <%= l.postalcode %>
                </td>
            </tr>
           <% end %>
           <% end %>
          </td>
        </table>
</table>

但是 /app/admin/postal_code.rb 中的代码 Active Admin Index view 给出了多个父列条目,每个第二列子条目一个。

ActiveAdmin.register PostalCode do
menu parent: "Region Settings"
permit_params :postalcode, :region_id


index do
 column :id
 column :region
 column "Postal Code" do |region|
   region.postalcode

end
end

在app/models/postal_code.rb

class PostalCode < ActiveRecord::Base
belongs_to :region
validates :region_id, presence: true
validates :postalcode, presence: true
# scope :region, -> (name) { }
# PostalCode.all.group_by(&:region_id)
end

并在 app/models/region.rb

class Region < ActiveRecord::Base
validates :name, presence: true
has_many :postalcodes
# has_many :produces, :through => :produceregionmonths
end

以下是如何使用 header 区域名称和

内的相应邮政编码创建这些单独的表
# app/admin/postal_code.rb

index do
  Region.all.each do |region|
    table_for(PostalCode.where(region_id: region.id), class: 'index_table') do
      column region.name do |postal_code|
        postal_code.postalcode
      end
      actions
    end
  end
end