ActiveAdmin is my favorite gem for creating admin features in Rails. It makes it so easy to create views to monitor and manage apps. Much of the heavy lifting is done for you by them gem.
I found that I need to do some tuning on my ActiveAdmin views to get the functionality I wanted without placing too heavy a burden on my server.
I mainly did this by doing two simple things:
(1) Specify Filters – if you don’t specify your filters, you may get far too many (and consuming too many resources when you don’t need to). Specifying filters are easy, just go into you admin files for the resource (i.e. app > admin > article.rb), then add a line for each filter you want
(2) Specify Index (and other) Columns – similar to above, if you don’t specify values, you may be receiving too much data. Be more efficient by only showing what you need to see in a view.
You can do this in your admin file for a resource, simply by adding this:
After I installed ActiveAdmin gem, everything worked great except I had an issue where the dropdown menus were showing ActiveRecord hashes like this:
Instead of showing a name like the other fields. It seems that the default is to show a field called “name” in the dropdown menus in ActiveAdmin, and if you don’t have such a field it shows the ActiveRecord instead. Changing that was easy, after I found this StackOverflow question.
All you have to do is go into the model and add a method for to_s, like this:
# field name you want to show in the drop down
for me, I put:
I was receiving a translation missing message that was showing up on my page views for my ActiveAdmin page. To correct this, I found the solution on Stack Overflow which said that these translations were just missing from my en.yml file in locales, and to replace my existing one with the one here (that ActiveAdmin uses):
The ActiveAdmin gem was working for me in development, but not in production. The reason, I found, was because not all of the assets used by ActiveAdmin were getting precompiled by Heroku. To solve the issue, I used the code by Ryan Long’s answer on Stack Overflow (in production.rb).
# Precompile additional assets. Defaults to [application.js, application.css, non-JS/CSS]
config.assets.precompile += ['active_admin.css', 'active_admin/print.css', 'active_admin.js']
My app was already using will_paginate extensively and I didn’t feel like changing it all to the Kaminari which ActiveAdmin uses for pagination.
However, somehow I was able to get it to work by thumbing through this ActiveAdmin issue. I created the initializer suggested by kml with this code:
Kaminari.configure do |config|
config.page_method_name = :bonzo # :)
However, when I implemented it, the code recommended for config/initializers/active_admin.rb caused me errors so I removed it. You may find that you need this code.