0

I have an Order resource, nested under User:

ActiveAdmin.register Order do
  belongs_to :user
end

# Routes at:
#  /admin/users/:user_id/orders/...

I would now also like to create an Order resource, for an overall view. Ideally I'd just do:

ActiveAdmin.register Order do
end

# Routes at:
#  /admin/orders/...

But this doesn't work, because it's creating the same underlying class (I assume).

it appears based on this that I should be able to use as: 'all_orders', but in fact this still appears to affect the same class, and ends up with routes like /admin/users/:user_id/all_orders/...

So, how can I have both order resources set up and operating independently, both using orders in the URL?

Community
  • 1
  • 1
Colin
  • 784
  • 2
  • 8
  • 21

2 Answers2

0

I think this might be the best option, as detailed here:

ActiveAdmin.register Order do
  belongs_to :user, optional: true
end

# Routes at:
#  /admin/orders/...
#  /admin/users/:user_id/orders/...

I would like to have the option of doing different things for the two, so an option where they can be separately defined would still be appreciated. If no better options are available I'll leave this answer here as it's reasonable.

Community
  • 1
  • 1
Colin
  • 784
  • 2
  • 8
  • 21
  • Actually not sure this does what I need, as I'm getting awkward errors... ideally I'd like to be able to use `only: :index` for the overall version, and then link to the user specific version for the rest. – Colin Oct 09 '13 at 11:12
0

Another solution, which is very hacky but does provide what I need is this:

# models/order.rb
class Order < ActiveRecord::Base
  belongs_to :user
end

 

# models/order_alias.rb
class OrderAlias < Order
end

 

# admin/user/order.rb
ActiveAdmin.register Order do
  belongs_to :user
end

 

# admin/order.rb
ActiveAdmin.register OrderAlias, as: 'AllOrder' do
  menu label: 'Orders'
  index title: 'Orders' do
    # ...
  end
end

This still has all_orders in the URL, but it's the closest to a solution I can find. Anything more elegant much appreciated.

Colin
  • 784
  • 2
  • 8
  • 21