Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a nested resource in activeadmin?

I have a resource called User and another one called Order.

I want Order to be nested inside Users so I can have these routes:

/users
/users/:id
/users/:id/new
/users/:id/edit
/users/:user_id/orders
/users/:user_id/orders/:id
/users/:user_id/orders/:id/new
/users/:user_id/orders/:id/edit

How can I do that with activeadmin?

like image 608
Bishma Stornelli Avatar asked Sep 11 '12 15:09

Bishma Stornelli


People also ask

What is active admin?

Active Admin is a framework for creating administration style interfaces. It abstracts common business application patterns to make it simple for developers to implement beautiful and elegant interfaces with very little effort.


2 Answers

Just add belongs_to option to active_admin resource page

ActiveAdmin.register Order do
  belongs_to :user
end
like image 131
railscard Avatar answered Sep 19 '22 07:09

railscard


@railscard's answer is partially correct, but if you don't want the default routes like /order, /order/:id etc like mentioned by @bishma-stornelli - you could add the option like this :

ActiveAdmin.register Order do
  belongs_to :user, :optional => true
end
like image 23
rohitpaulk Avatar answered Sep 23 '22 07:09

rohitpaulk