2016-09-18 72 views
0

我構建了一個簡單的電子商務應用程序,並且使用活動管理面板進行管理。我的問題是這樣的。Rails和Active Admin嵌套資源

我有兩個模型訂單& order_items。 order_items保存訂單產品。該關聯是order - > has_many order_items & order_items - > belongs_to命令。

我有這個代碼在活動管理,但我看不到訂單(空白)的項目。

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 

我可以達到order_items扔控制檯,所以模型關聯沒有問題。

+0

確定實際上已經連接到它的ORDER_ITEMS順序? – DMH

回答

0

嘗試沿着此線的東西:

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 
+0

你幫了我很多,但我選擇了另一種方式。我爲order_items創建了一個不同的菜單,並將訂單鏈接自動過濾order_items並僅顯示此訂單商品。這是代碼:''列「產品」,::order_item do |我| link_to i.order_items.count,admin_order_items_path('q [order_id_equals]'=> i.id) end'' – elgreko

+0

真棒很高興我可以幫助 – DMH