A user has_many transactions. I have active admin currently set to nest the transactions under user for basic CRUD using belongs_to :user in admin/transactions.rb. I also, however, need a top level view for transactions that shows a subset of transaction records that span across users. How can I accomplish this second part?
I think the best way now is to pass in the "optional" option:
ActiveAdmin.register Transactions do
belongs_to :user, :optional => true
...
end
This way, you'll get to access all Transactions from the main navigation menu as well as the nested view under a particular User.
If you want to find more, you can refer to the source code under:
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
You need to create two Active Admin resources that both refer to the same Active Record Model that needs nested and unnested routes.
The parent resource:
ActiveAdmin.register ParentClass do
end
The nested resource:
ActiveAdmin.register ChildClass do
belongs_to :parent_class
end
The unnested resource:
ActiveAdmin.register ChildClass, :as => "All Children" do
end
You'll now have direct access to ChildClass via the "All Children" tab without getting an error that the ParentClass is missing while still enjoying the nested access to the ChildClass from the ParentClass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With