Add custom items at header menu in ActiveAdmin
I want to add a link like link_to ("Edit yout profile", edit_user (current_user)) at header in ActiveAdmin. Is that possible ?!
Solution 1:
Recent versions of ActiveAdmin allow you to do this in your active_admin.rb
initializer:
config.namespace :admin do |admin|
admin.build_menu do |menu|
menu.add :label => 'Custom Menu' do |submenu|
submenu.add :label => 'Custom Link', :url => custom_path
end
end
end
Solution 2:
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
Solution 3:
If you're using a later version of ActiveAdmin that has the capability for custom pages, you can do the following:
ActiveAdmin.register_page "Store Admin" do
controller do
define_method(:index) do
redirect_to "/store/admin"
end
end
end
This overrides the index
action of the PageController which normally just renders the page, but you can instead have it redirect to wherever you want to go, such as edit_user_path