Is there a way to add another menu level with Active Admin?

I am using Active Admin and trying to add another level to the drop-down menu. In the documentation, I see that I can impose one level with this code:

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

Thanks for any help.

Edited by:

I want something like this:

 Menu 1 ^ Menu 2 > Menu A Menu B Menu 3 
+4
source share
2 answers

I decided to fix this problem by overwriting the ActiveAdmin menu. It was also necessary to create new CSS in the new menu.

Tell ActiveAdmin that we will use the header itself. To do this, add the following lines to the config / initializers / active_admin.rb file :

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

Create a CustomAdminHeader class that will contain code that will overwrite the build menu. You can create this class in the / admin application and name it as custom_admin_header.rb . And add this code to create a 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 options used in the classes contained in the app / admin folder should not be displayed. To do 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 CSS for the new menu.

I posted this solution on my blog:

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

I hope this will be useful to everyone.

+5
source

If you put several resources under the same parent in the menu, then the drop-down list will have a level for each of these resources. In the example below, the Blog tab drops out of the menu with posts and comments in it. All you need to do to add additional resources to the Blog drop-down list is their menu :parent => "Blog"

Publication resource

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

Comment resource

 ActiveAdmin.register Comment do menu :parent => "Blog" end 
+1
source

Source: https://habr.com/ru/post/1469117/


All Articles