[英]Active Admin: dedicated index page for a resource that uses belongs_to
Rails 5 (Ruby 2.5.1), activeadmin 2.2.0 Rails 5(Ruby 2.5.1),activeadmin 2.2.0
I have a resource B that belongs to a resource A so I can list index views of B that belong to an instance of A. 我有一个属于资源A的资源B,因此我可以列出属于A实例的B的索引视图。
ActiveAdmin.register B do
menu false
belongs_to :A
end
ActiveAdmin.register A do
menu 'A'
end
When I try to create an index page for all instances of B independently from A, using this code: 当我尝试使用以下代码为B的所有实例独立于A创建索引页时:
ActiveAdmin.register B do
menu false
belongs_to :A
actions :index
index do
id_column
end
end
it does not generate a dedicated index path. 它不会生成专用的索引路径。 When I remove
belongs_to
though, I get a dedicated path and the expected index view for resource B. But I lose the functionality on resource A that come with belongs_to
. 但是, 当我删除
belongs_to
,我得到了专用路径和资源B的预期索引视图。但是我丢失了belongs_to
附带的资源A上的功能。
How can I keep the association and have a general index page for resource B? 我如何保持关联并为资源B提供一个常规索引页?
The documentation says that to achive this, you pass in optional: true
to the belongs_to
directive. 该文件说,为实现这一目标,你在通过
optional: true
的belongs_to
指令。 So registering B would be like: 因此,注册B就像:
ActiveAdmin.register B do
menu false
belongs_to :A, optional: true
actions :index
index do
id_column
end
end
I put together this application to illustrate. 我将这个应用程序放在一起进行说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.