简体   繁体   English

活动管理资源的下拉菜单

[英]Drop-down menu for active admin resource

I'm trying to create a drop down menu in active admin's navigation.我正在尝试在活动管理员的导航中创建一个下拉菜单。 The docs:文档:

https://activeadmin.info/2-resource-customization.html#customize-the-menu https://activeadmin.info/2-resource-customization.html#customize-the-menu

says all I need to do is create the menu:说我需要做的就是创建菜单:

    config.namespace :admin do |admin|
      admin.build_menu do |menu|
        menu.add label: 'example', priority: 0
      end
    end

then add that menu as the parent of the resource:然后将该菜单添加为资源的父级:

menu parent: 'example'

But that doesn't work for me.但这对我不起作用。

The only thing that has thus far is this:到目前为止唯一的事情是这样的:

    config.namespace :admin do |admin|
      admin.build_menu do |menu|
        menu.add label: 'Appointment', priority: 0, html_options: { target: :blank } do |item|
          item.add label: 'Appointment',  url: '/admin/appointments'
          item.add label: 'AppointmentCommunication',  url: '/admin/appointment_communications'
        end
      end
    end

With menu: false in the actual resource file. with menu: false 在实际资源文件中。

But that's pretty messy, and not well organized.但这很乱,而且组织得不好。 I was hoping to have a simpler way of making the menus.我希望有一种更简单的方法来制作菜单。 But maybe I'm just missing something.但也许我只是错过了一些东西。

Note: I did try to name the menu something that wasn't the name of one of the resources but alas no changes.注意:我确实尝试将菜单命名为不是资源之一的名称,但没有更改。 Additionally, I tried moving the two resources - Appointment and AppointmentCommunication - into a folder called Appointment but obviously that didn't work.此外,我尝试将两个资源 - Appointment 和 AppointmentCommunication - 移动到名为 Appointment 的文件夹中,但显然这不起作用。

Any thoughts on this would be appreciated.对此的任何想法将不胜感激。

It should work as in the docs它应该像在文档中一样工作

# app/admin/appointment.rb
  menu label: 'Appointment', parent: 'Appointments', priority: 0

# app/admin/appointment_communication.rb
  menu label: 'Appointment Communication', parent: 'Appointments', priority: 1

A couple of options:几个选项:

  1. You can just add the parent menu in the resource and it will work without defining it:您只需在资源中添加父菜单,它就可以在不定义它的情况下工作:
 menu parent: 'site'

site will become the dropdown name and resource(s) will be menu items. site将成为下拉名称,资源将成为菜单项。

  1. You can define the parent menu in the initializers/active_admin.rb :您可以在initializers/active_admin.rb定义父菜单:

config.namespace :admin do |admin| config.namespace :admin 做 |admin| super_admin.site_title = "Active Admin" super_admin.site_title = "活跃管理员"

 admin.build_menu do |menu| menu.add label: 'Configuration', priority: 0 end

One thing to note is, if you go with option #2, you have to restart your server in order to view the changes.需要注意的一件事是,如果您选择选项 #2,则必须重新启动服务器才能查看更改。

Source: https://activeadmin.info/2-resource-customization.html#customize-the-menu来源: https : //activeadmin.info/2-resource-customization.html#customize-the-menu

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

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