Skip to content

Instantly share code, notes, and snippets.

@gregbell
Created February 23, 2012 18:11
Show Gist options
  • Save gregbell/1894179 to your computer and use it in GitHub Desktop.
Save gregbell/1894179 to your computer and use it in GitHub Desktop.
Example of changing the utility navigation in the layout (Top right of nav bar)
# This assumes you are using that you are using Active Admin from master.
# You can do this with 0.4.2 but you would need to override the HeaderRenderer instead
# config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
# View a list of all the elements you can override
# https://github.com/gregbell/active_admin/blob/master/lib/active_admin/view_factory.rb
config.view_factory.utility_navigation = MyCustomUtilityNav
end
# The subclass the utility nav
class MyCustomUtilityNav < ActiveAdmin::Views::UtilityNav
# Override the build method which accepts the current ActiveAdmin::Namespace
def build(namespace)
span("Hello From My Utility Nav")
super(namespace)
end
end
# OR Create a whole new utility nav
class MyCustomUtilityNav < ActiveAdmin::Component
def build(namespace)
span("Hello From My Utility Nav")
end
def tag_name
'p'
end
end
@zef
Copy link

zef commented Oct 9, 2012

Never mind, this works as expected. I was experiencing the problem because I had tried to scope ActiveAdmin within routes.rb, which messed up the paths.

I had tried this:

scope '/admin', as: :admin do
  ActiveAdmin.routes(self)
end

And was registering some resources with namespace: false so I could have other namespaces nested within /admin/. I still don't have a good solution for doing that, but I'm just using other routes for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment