ruby on rails 4 - How do you add a second column of 'children' without duplicating the 'parent' column entry in Active Admin? -
this table, raw table correct output, result looking for, how translate block of code whatever active admin /app/admin/postal_code.rb index view requires output table correctly.
currently block rendered in partial, /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 |region| %> <tr> <td><%= region.name %></td> <td> <table> <% list = @postalcode.where("region_id=#{region.id}") %> <% list.each |l| %> <tr> <td width="5%"> <%= l.postalcode %> </td> </tr> <% end %> <% end %> </td> </table> </table>
but code, active admin index view, in /app/admin/postal_code.rb giving multiple parent column entries, 1 each second column child entry.
activeadmin.register postalcode menu parent: "region settings" permit_params :postalcode, :region_id index column :id column :region column "postal code" |region| region.postalcode end end
in 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
and in app/models/region.rb
class region < activerecord::base validates :name, presence: true has_many :postalcodes # has_many :produces, :through => :produceregionmonths end
here's how can create individual tables header of region name , corresponding postalcodes inside
# app/admin/postal_code.rb index region.all.each |region| table_for(postalcode.where(region_id: region.id), class: 'index_table') column region.name |postal_code| postal_code.postalcode end actions end end end
Comments
Post a Comment