coda
coda

Reputation: 303

Drop-down menu for active admin resource

I'm trying to create a drop down menu in active admin's navigation. The docs:

https://activeadmin.info/2-resource-customization.html#customize-the-menu

says all I need to do is create the menu:

    config.namespace :admin do |admin|
      admin.build_menu do |menu|
        menu.add label: 'example', priority: 0
      end
    end

then add that menu as the parent of the resource:

menu parent: 'example'

But that doesn't work for me.

The only thing that has thus far is this:

    config.namespace :admin do |admin|
      admin.build_menu do |menu|
        menu.add label: 'Appointment', priority: 0, html_options: { target: :blank } do |item|
          item.add label: 'Appointment',  url: '/admin/appointments'
          item.add label: 'AppointmentCommunication',  url: '/admin/appointment_communications'
        end
      end
    end

With menu: false in the actual resource file.

But that's pretty messy, and not well organized. I was hoping to have a simpler way of making the menus. But maybe I'm just missing something.

Note: I did try to name the menu something that wasn't the name of one of the resources but alas no changes. Additionally, I tried moving the two resources - Appointment and AppointmentCommunication - into a folder called Appointment but obviously that didn't work.

Any thoughts on this would be appreciated.

Upvotes: 0

Views: 2723

Answers (2)

Malay
Malay

Reputation: 713

A couple of options:

  1. You can just add the parent menu in the resource and it will work without defining it:

menu parent: 'site'

site will become the dropdown name and resource(s) will be menu items.

  1. You can define the parent menu in the initializers/active_admin.rb:
config.namespace :admin do |admin|
  super_admin.site_title = "Active Admin"  
  admin.build_menu do |menu|
    menu.add label: 'Configuration', priority: 0
 end
end

One thing to note is, if you go with option #2, you have to restart your server in order to view the changes.

Source: https://activeadmin.info/2-resource-customization.html#customize-the-menu

Upvotes: 1

NeverBe
NeverBe

Reputation: 5038

It should work as in the docs

# app/admin/appointment.rb
  menu label: 'Appointment', parent: 'Appointments', priority: 0

# app/admin/appointment_communication.rb
  menu label: 'Appointment Communication', parent: 'Appointments', priority: 1

Upvotes: 0

Related Questions