Created
February 23, 2012 18:11
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
Been trying to get this working. As soon as I have a class that inherits from ActiveAdmin::Views::UtilityNav or ActiveAdmin::Component, I am getting this error:
Any ideas? Do you expect this kind of thing to work still? I'm using 0.5.0. I've looked around the codebase and haven't found out what is wrong.
Thanks so much.