Tiago
Tiago

Reputation: 733

Multi level menus in active admin

Is there a way to create multi level menu in Active Admin (more than two levels of deepness), while some of the entries are not models?

Something like:

1 - Some_text 1.1 - Model_1 1.1.1 - Model_2 1.2 - Some_other_text 1.2.1 - Model_3 1.2.2 - Model_4 1.3 - Model_5 2 - Some_more_text 2.1 - Model_6 2.2 - Model_7 3 - Model_8

I haven't found a way to do this (I checked the gem subnav but it doesn't allow me to have plain text as a menu entry: it has to be a model).

Any suggestions are welcome. Thank you

Upvotes: 1

Views: 535

Answers (1)

Tiago
Tiago

Reputation: 733

The way to do this was to create an ActiveAdmin::Views::Header. Like the following one:

class CustomAdminHeader < ActiveAdmin::Views::Header
  include Rails.application.routes.url_helpers

  def build(namespace, menu)
    div class: 'c-nav' do
      div class: 'logo' do
        image_tag(image_url("logo.svg"))
      end
      div class: 'list' do
        # Add one item without son.
        ul do
          # Replace route_destination_path for the route you want to follow when you receive the item click.
          li { link_to 'Dashboard', admin_dashboard_path }
        end

        # Add one item with one son.
        ul do
          li do
            text_node content_tag 'a', 'Animals'
            ul do
              li { link_to 'Cats',         admin_cats_path }
              li { link_to 'Dogs',     admin_dogs_path }
              li { link_to 'Wolves',          admin_wolves_path }
              li { link_to 'Cows',         admin_cows_path }
              li do
                text_node content_tag 'a', 'Settings', class: '-with-children'
                ul do
                  li { link_to 'Categories',             admin_categories_path }
                  li { link_to 'Subcategories',          admin_subcategories_path }
                  li { link_to 'Colors',             admin_colors_path }
                  li { link_to 'Sizes',                   admin_sizes_path }
                  li { link_to 'Sounds',    admin_sounds_path }
                  li { link_to 'Species',                admin_species_index_path }
                end
              end
            end
          end
        end
...

Upvotes: 2

Related Questions