I want to add a link like link_to (\"Edit yout profile\", edit_user (current_user)) at header in ActiveAdmin. Is that possible ?!
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
according to the post that @phoet mentioned, (https://stackoverflow.com/a/7218598/445908) try this code:
module ActiveAdmin
module Views
class HeaderRenderer
def to_html
title + global_navigation + profile_link + utility_navigation
end
def profile_link
link_to ("Edit yout profile", edit_user (current_user))
end
end
end
end
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
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
To me the @kristinalim answer almost work but his custom_path do not work, this give me a error. The next code work for me (I have to define the routes)
routes = Rails.application.routes.url_helpers
config.namespace :admin do |admin|
admin.build_menu do |menu|
menu.add :label => 'Custom Menu' do |submenu|
submenu.add label: 'Users', url: routes.admin_users_path
end
end
end