Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a parent menu priority in ActiveAdmin?

I have a couple of models in my Ruby on Rails application like "Plan", "Tester", "Module", etc. Using activeadmin gem, I would like to have a page for each of these entities and place each under a couple of different menus. So my code looks like the following:

ActiveAdmin.register Plan do
  menu parent: 'Planning', priority: 1

ActiveAdmin.register Tester do
  menu parent: 'Planning', priority: 2

ActiveAdmin.register Module do
  menu parent: 'Bundle', priority: 1

ActiveAdmin.register User do
  menu parent: 'Administration', priority: 1

I don't have a page for the top menus ('Planning', 'Bundle', 'Administration'), but I want to see them in a custom order and not the alphabetical order. So, my question is how could I set the priority (order) of the parent menus without having a corresponding page for each of them?

like image 740
moorara Avatar asked Feb 17 '15 17:02

moorara


2 Answers

The items, which non model-based starts their priority from 10, so u can put 10+ priority for model-based menus. If you need to set priorities among non model-based menus, you can build fake file under admin folder like admin/administration.rb with code:

ActiveAdmin.register_page "Administration" do
  menu :label => "Administration", :priority => 15, :url => '#'
end

and admin/bundle.rb:

ActiveAdmin.register_page "Bundle" do
  menu :label => "Bundle", :priority => 16, :url => '#'
end

so on

like image 165
dsounded Avatar answered Nov 02 '22 22:11

dsounded


See 'Customizing Parent Menu Items' in the documentation.

# config/initializers/active_admin.rb
config.namespace :admin do |admin|
  admin.build_menu do |menu|
    menu.add label: 'Blog', priority: 0
  end
end

# app/admin/post.rb
ActiveAdmin.register Post do
  menu parent: 'Blog'
end
like image 44
Piers C Avatar answered Nov 02 '22 22:11

Piers C