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

我正在使用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/

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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...