Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails ActiveAdmin - get current_admin_user in utility navigation?

The ActiveAdmin docs say that I can override the utility navigation like this:

ActiveAdmin.setup do |config|
  config.namespace :admin do |admin|
    admin.build_menu :utility_navigation do |menu|
      menu.add label: "ActiveAdmin.info", url: "http://www.activeadmin.info", html_options: { target: :blank }
      admin.add_logout_button_to_menu menu # can also pass priority & html_options for link_to to use
    end
  end
end

It also says that the default display includes the current user's email address. How does it get the current user's email address? When I try replacing the menu.add label value with current_admin_user I get an error that says current_admin_user is undefined. How do I access info about the currently signed in user from the config file? How does ActiveAdmin do it behind the scenes?

like image 281
Kvass Avatar asked Jul 11 '13 03:07

Kvass


2 Answers

config.namespace :admin do |admin|
      admin.build_menu :utility_navigation do |menu|
         menu.add  :label  => proc{ display_name current_active_admin_user },
                  :url    =>  proc{  edit_admin_admin_user_path(current_active_admin_user) }  ,#link_to current_active_admin_user,
                  :id     => 'current_user',
                  :if     => proc{ current_active_admin_user? }
        admin.add_logout_button_to_menu menu
      end
    end
like image 169
Fivell Avatar answered Nov 13 '22 07:11

Fivell


Just try the following:

ActiveAdmin.setup do |config|
  config.namespace :admin do |admin|
    admin.build_menu :utility_navigation do |menu|
      menu.add label: "ActiveAdmin.info", url: "http://www.activeadmin.info",
                                      html_options: { target: :blank }
      admin.add_current_user_to_menu  menu
      admin.add_logout_button_to_menu menu
    end
  end
end
like image 3
G. I. Joe Avatar answered Nov 13 '22 05:11

G. I. Joe