简体   繁体   English

如何在ActiveAdmin中设置父菜单优先级?

[英]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. 我的Ruby on Rails应用程序中有几个模型,如“Plan”,“Tester”,“Module”等。使用activeadmin gem,我想为每个实体创建一个页面,并将每个模块放在几个不同的菜单。 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. 我没有顶级菜单的页面('Planning','Bundle','Administration'),但我希望以自定义顺序而不是字母顺序看到它们。 So, my question is how could I set the priority (order) of the parent menus without having a corresponding page for each of them? 所以,我的问题是如何设置父菜单的优先级(顺序),而不是每个菜单都有相应的页面?

The items, which non model-based starts their priority from 10, so u can put 10+ priority for model-based menus. 非基于模型的项目从10开始优先级,因此您可以为基于模型的菜单提供10+优先级。 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: 如果您需要在非基于模型的菜单中设置优先级,您可以在管理员文件夹下构建假文件,例如admin / administration.rb,代码如下:

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

and admin/bundle.rb: 和admin / bundle.rb:

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

so on 等等

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM