Customizing Active Admin
I came across a new Ruby on Rails administration framework yesterday called Active Admin, thanks to the latest instalment (episode 165) of The Ruby Show.
I was immediately impressed by the professional landing page and the look and feel of the administration views generated by the gem. I was also very impressed by the elegant DSL. Active Admin is packaged as a gem and it abstracts away all of the tedious administration coding into a simple DSL. The administration files are tucked away under the app folder into a folder of it’s own called admin, and there is one file per resource. I decided to give it a spin and see what it could do.
While playing around with it for an hour or so, I decided to see how far I could push it. Just how flexible is this framework. I added 15 resources to manage in the admin. This pushed the limit of visibility for the menu items at the top of the page, causing them to wrap. It looked ugly and where some resources were two of more words I found the menu item itself would break and wrap splitting the menu item over several lines. I noticed in the screenshot on the Active Admin web site that the Administration menu item had a disclosure indicator. This hinted that the menus could be nested, so I decided to look into it. I found some undocumented options on the menu method, one of which is :parent. By setting a parent you can nest menu items for resources under a top-level menu, and this creates a CSS dropdown menu.
This code generates an Administration menu with three menu items in a dropdown:
# app/admin/administration.rb ActiveAdmin.register Manager do menu :parent => "Administration" end ActiveAdmin.register Backup do menu :parent => "Administration" end ActiveAdmin.register Setting do menu :parent => "Administration" end
and it looks like this:

Another little thing that was slightly annoying was the attribution in the footer. There doesn’t seem to be provision to set the content displayed in the footer of the administration views. I’ve found that Ruby comes to your aid for things like this and by overriding the right method you can put whatever you want in the footer.
The following code overrides the footer content:
# lib/active_admin_views_pages_base.rb
class ActiveAdmin::Views::Pages::Base < Arbre::HTML::Document
private
# Renders the content for the footer
def build_footer
div :id => "footer" do
para "Copyright © #{Date.today.year.to_s} #{link_to('Example.com', 'http://example.com')}. Powered by #{link_to('Active Admin', 'http://www.activeadmin.info')} #{ActiveAdmin::VERSION}".html_safe
end
end
end
# app/controllers/application_controller.rb class ApplicationController < ActionController::Base protect_from_forgery # Override build_footer method in ActiveAdmin::Views::Pages require 'active_admin_views_pages_base.rb' end
So far I haven’t found anything that’s restricting the way I want the administration views to function. I’ll be playing around with nested models and things like datetime pickers over the next day or so. I’ll post if I find anything tricky. I’m keen to hear your thoughts on Active Admin.