如果我有三个资源, 当我在一个资源中声明belongs_to时,它运行良好
ActiveAdmin.register Order
ActiveAdmin.register Material do
belongs_to :order
end
这会在
下生成路径batch_action_admin_order_materials POST /admin/orders/:order_id/materials/batch_action(.:format) admin/materials#batch_action
admin_order_materials GET /admin/orders/:order_id/materials(.:format) admin/materials#index
POST /admin/orders/:order_id/materials(.:format) admin/materials#create
new_admin_order_material GET /admin/orders/:order_id/materials/new(.:format) admin/materials#new
edit_admin_order_material GET /admin/orders/:order_id/materials/:id/edit(.:format) admin/materials#edit
admin_order_material GET /admin/orders/:order_id/materials/:id(.:format) admin/materials#show
PATCH /admin/orders/:order_id/materials/:id(.:format) admin/materials#update
PUT /admin/orders/:order_id/materials/:id(.:format) admin/materials#update
DELETE /admin/orders/:order_id/materials/:id(.:format) admin/materials#destroy
但是,当我添加set相同的资源属于另一个资源时,上面的路径都消失了,而是在下面生成路径
ActiveAdmin.register Supplier
ActiveAdmin.register Material do
belongs_to :supplier
end
batch_action_admin_supplier_materials POST /admin/suppliers/:supplier_id/materials/batch_action(.:format) admin/materials#batch_action
admin_supplier_materials GET /admin/suppliers/:supplier_id/materials(.:format) admin/materials#index
POST /admin/suppliers/:supplier_id/materials(.:format) admin/materials#create
new_admin_supplier_material GET /admin/suppliers/:supplier_id/materials/new(.:format) admin/materials#new
edit_admin_supplier_material GET /admin/suppliers/:supplier_id/materials/:id/edit(.:format) admin/materials#edit
admin_supplier_material GET /admin/suppliers/:supplier_id/materials/:id(.:format) admin/materials#show
PATCH /admin/suppliers/:supplier_id/materials/:id(.:format) admin/materials#update
PUT /admin/suppliers/:supplier_id/materials/:id(.:format) admin/materials#update
DELETE /admin/suppliers/:supplier_id/materials/:id(.:format) admin/materials#destroy
我希望拥有这两条路径并且不希望它们消失。 任何人都可以提供帮助,谢谢!
答案 0 :(得分:0)
好的,问题是你正在写ActiveAdmin.register Material
两次 - 第二个是覆盖第一个。
(也不是你应该使用belongs_to行的小写)
不要写两次,而是将belongs_to
写入其中一次,例如:
ActiveAdmin.register Order
ActiveAdmin.register Supplier
ActiveAdmin.register Material do
belongs_to :order
belongs_to :supplier
end
答案 1 :(得分:0)
可能您可以尝试重命名资源:Rename Resource
所以你的材料.rb会得到:
ActiveAdmin.register Material do
belongs_to :order
end
您可以创建新文件supplier_materials.rb,其中包含:
ActiveAdmin.register Material, as: "Supplier Material" do
belongs_to :supplier
end
这可以作为两个独立的资源。