Add custom items at header menu in ActiveAdmin

后端 未结 5 1671
暖寄归人
暖寄归人 2021-01-08 01:01

I want to add a link like link_to (\"Edit yout profile\", edit_user (current_user)) at header in ActiveAdmin. Is that possible ?!

5条回答
  •  半阙折子戏
    2021-01-08 01:28

    For recent versions of active admin, there are two solutions, both kind of unfortunate.

    Any of your Resources with menu false can be set to menu label: "Google", url: "http://www.google.com". This is unfortunate because it is highlighted as selected if you are on the resource from which you set it.

    The other solution is to over-write the ActiveAdmin::Views::Header as above, but updated.

    module ActiveAdmin
      module Views
        class Header < Component
    
          def build_global_navigation
            item = ActiveAdmin::MenuItem.new(label: "google", url: "http://www.google.com")
            @menu.add item
            insert_tag view_factory.global_navigation, @menu, :class => 'header-item'
          end
        end
      end
    end
    

    This doesn't work exactly right, as you can't set things like parent: "Developer" for the menu item... Anyway, I may make a fork so you can add items in the initializer to a particular namespace...Did anyone open an issue for this? I didn't see one.

    Update: I think this is the cleanest way to implement this (without contributing to active admin).

    ActiveAdmin.register_page "Queue" do
      menu parent: "Developer", url: '/admin/resque'
    end
    

提交回复
热议问题