Last Updated: August 25, 2017
·
53
· MaverickRolex

Active Admin - Customize the added menus

This tip will change the user data displayed on the menu from active admin, the original configuration print the user email from the current user. To change the email for the user_name,

On file "appfolder/config/initializers/activeadmin.rb" add the next code:

config.namespace :admin do |admin|
admin.buildmenu :utilitynavigation do |menu|
menu.add label: "Storage", url: Rails.application.routes.urlhelpers.storagespath
menu.add label: "Transferences", url: Rails.application.routes.urlhelpers.itemtransferspath
menu.add :label => proc{ current
activeadminuser.userfullname },
:url => proc { adminuserpath(currentuser.id) },
:id => 'current
user'
admin.addlogoutbuttontomenu menu
end

end

To see the changes we must restart the server in the terminal, and the user email from the current user was change for the user name.
However when doing this the name will convert in a menu item not an admin menu, so that will cause the buttons to be organized alphabetically

to fixed we must add priority to menu objects with this:

menu.add label: "Storage", priority: 0, url: Rails.application.routes.urlhelpers.storagespath
menu.add label: "Transferences", priority: 1, url: Rails.application.routes.urlhelpers.itemtransferspath
menu.add :label => proc{ current
activeadminuser.userfullname },
:url => proc { adminuserpath(current_user.id) },

:id => 'current_user'

Restart the server and see how the menu has the original structure but displaying the user name instead of the user email.