简体   繁体   English

活动管理员:专用的索引页面,用于使用belongs_to的资源

[英]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: truebelongs_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.

相关问题 关联关系属部到的活动管理员覆盖表单页面 - active admin overide form page with relation belongs_to 向Active Admin添加项目归属关系 - adding items belongs_to relationship to Active Admin 无法在关联模型的Active Admin索引属性中显示(longs_to / has_many)-Rails 3.2 - Can't display in Active Admin index attribute of associated model (belongs_to/has_many) - Rails 3.2 如何使用belongs_to / has_many关系在Active Admin索引中显示关联模型的属性(Rails 3.2 / Active Admin) - How to display associated model's attribute in Active Admin index with belongs_to/has_many relationship (Rails 3.2/Active Admin) 调用索引页面中的belongs_to中的属性 - Calling attributes in belongs_to in the index page 具有active_admin和belongs_to关系的rails4-autocomplete gem - rails4-autocomplete gem with active_admin and belongs_to relation Active Admin:在Rails 4中,longate_to提供“未定义的方法”错误 - Active Admin: belongs_to giving “undefined method” Error in Rails 4 可选的belongs_to,用于重命名的active_admin资源 - optional belongs_to for renamed active_admin resources 按归属关系中的父项排序active_admin列 - order active_admin column by parent item in belongs_to relationship 两级深度belongs_to关联上的Active Admin过滤器 - Active Admin filter on two-level deep belongs_to association
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM