加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 无论如何使用Active Admin添加其他级别的菜单

发布时间:2020-12-17 03:39:42 所属栏目:百科 来源:网络整理
导读:我正在使用Active Admin并尝试在下拉菜单中添加其他级别.在文档中,我看到我可以使用此代码放置一个级别: ActiveAdmin.register Post do menu :parent = "Blog" end 谢谢你的帮助. 编辑: 我想要这样的东西: Menu 1 ^Menu 2 Menu A Menu BMenu 3 解决方法
我正在使用Active Admin并尝试在下拉菜单中添加其他级别.在文档中,我看到我可以使用此代码放置一个级别:

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

谢谢你的帮助.

编辑:

我想要这样的东西:

Menu 1 ^
Menu 2 > Menu A
         Menu B
Menu 3

解决方法

我解决了这个问题,覆盖了ActiveAdmin的菜单.还需要为新菜单创建一个新的CSS.

通知ActiveAdmin我们将使用标头本身.为此,在config / initializers / active_admin.rb文件中添加以下行:

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

创建一个名为CustomAdminHeader的类,该类将包含将覆盖构造菜单的代码.您可以在app / admin中创建此类,并将该文件命名为custom_admin_header.rb.并添加此代码以创建新菜单:

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

菜单的结构将由此类创建,因此不应显示文件夹app / admin中包含的类中使用的菜单设置.为此,您需要在所有类中添加以下代码:

menu false

最后,您需要创建一个名为new_menu.css的CSS文件,并为新菜单添加CSS.

我在我的博客上发布了这个解决方案

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

我希望它对任何人都有帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读