elgreko elgreko - 2 months ago 18
Ruby Question

Rails and Active Admin Nested Resources

I build a simple ecommerce app and i am using active admin for administration panel. My problem is this.

i have two models orders & order_items. order_items saves the orders products. The association is order -> has_many order_items & order_items -> belongs_to orders.

I have this code in active admin but i can't see the items of an order(blank).

index :title => 'orders' do
selectable_column
id_column
column "value", :subtotal
column "tax", :tax
column "shipping", :shipping
column "total value", :total
column "status", :order_status_id
column "created_at", :created_at
column "updated_at", :updated_at
column "order_items", :order_items
actions
end


I can reach order_items throw console so there is no problem with the model associations.

DMH DMH
Answer

Try something along the lines of this:

index :title => 'orders' do
  selectable_column
  id_column
  column "value", :subtotal
  column "tax", :tax
  column "shipping", :shipping
  column "total value", :total
  column "status", :order_status_id 
  column "created_at", :created_at 
  column "updated_at", :updated_at
  column :order_items, sortable: true do | item |
    item.id # this could be any attribute attached to the order_item table 
  end
  actions
end