How can I have an Active Admin view of nested and non-nested resources?

The user has several transactions. I have an active administrator who is currently configured to nest transactions under a user for a basic CRUD using own_to: user in admin / transaction.rb. However, I also need a top-level view for transactions, which displays a subset of transaction records that span users. How can I complete this second part?

+7
source share
2 answers

I think it's best to go to the "optional" option:

ActiveAdmin.register Transactions do belongs_to :user, :optional => true ... end 

Thus, you will get access to all transactions in the main navigation menu, as well as a subview under a specific user.

If you want to find more, you can refer to the source code in the section:

https://github.com/gregbell/active_admin/blob/0.4.x-stable/lib/active_admin/resource.rb

Line 131

 def include_in_menu? super && !(belongs_to? && !belongs_to_config.optional?) end 
+19
source

You need to create two Active Admin resources that belong to the same Active Record Model, which needs nested and unnamed routes.

Parent resource:

 ActiveAdmin.register ParentClass do end 

Nested resource:

 ActiveAdmin.register ChildClass do belongs_to :parent_class end 

Fatal resource:

 ActiveAdmin.register ChildClass, :as => "All Children" do end 

You will now have direct access to ChildClass through the "All Children" tab, without receiving the error that ParentClass passes, but still enjoying the nested access to ChildClass from ParentClass.

+7
source

All Articles