Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to add another levels of menus with Active Admin?

I'm using Active Admin and trying add another levels at drop down menu. In documentation I see that I can put one level using this code:

  ActiveAdmin.register Post do
    menu :parent => "Blog"
  end

Thanks for any help.

Edited:

I want something like that:

Menu 1 ^
Menu 2 > Menu A
         Menu B
Menu 3
like image 519
monteirobrena Avatar asked Dec 26 '22 07:12

monteirobrena


1 Answers

I got fix this problem overwriting the menu of ActiveAdmin. It was also necessary create a new CSS to the new menu.

Inform the ActiveAdmin that we will use a header itself. To this add the following lines in the file config/initializers/active_admin.rb:

config.view_factory.header = CustomAdminHeader
config.register_stylesheet 'new_menu.css'

Create a class called CustomAdminHeader that will contain the code that will overwrite the construction menu. You can create this class within the app/admin and name the file as custom_admin_header.rb. And add this code to create the new menu:

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

  def build(namespace, menu)
    div :id => 'tabs' 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 'Item without son', route_destination_path }
      end

      # Add one item with one son.
      ul do
        li do
          text_node link_to("Parent with 1 child", "#")
          ul do
            li { link_to 'Son without child', route_destination_path }
            # If you want to add more children, including more LIs here.
          end
        end
      end

      # Adds a menu item with one son and one grandson.
      ul do
        li do
          text_node link_to("Grandmother with 1 child", "#")
          ul do
            li do
              text_node link_to("Parent with 1 child", route_destination_path)
              ul do
                li { link_to 'Grandson without child', route_destination_path }
                # If you want to add more grandchildren, including more LIs here.
              end
            end
          end
        end
      end

    super(namespace, menu)
  end
end

The structure of your menu will be created by this class so the menu settings used in the classes contained in the folder app/admin should not be displayed. For this you need to add the following code in all classes:

menu false

Finally you need to create a CSS file called new_menu.css and add the CSS for the new menu.

I posted this solution at my blog:

http://monteirobrena.wordpress.com/2013/05/07/activeadmin-customizacao-do-menu/

I hope it's helpful for anyone.

like image 106
monteirobrena Avatar answered May 11 '23 10:05

monteirobrena