Ruby DevBlog by Jesse Wolgamott

The One Where ActiveAdmin and Mongoid Get Along

So you like ActiveAdmin, but are using Mongoid. And so far, ActiveAdmin hates on Mongoid because it uses ActiveRecord instead of ActiveModel. What’s a Mongoid to do? Develop your own admin system? As If!

First, Watch this Issue

There’s already a github issue about adding support for other ORMs. Maybe voice your support there.

Then, Monkey Patch!

Add this code to your config/initializers/active_active_for_mongoid.rb

It’s easy to tell what’s going on with the code – ActiveAdmin needs a way to tell what the name of the collection is (otherwise you get the quoted_table_name problem). Mongoid also has some custom ways of sorting. For example,

Product.order("published_at DESC").all
Product.all(sort: [[ :published_at, :desc ]])

The mongo queries that get executed look like:

MONGODB yourapp_development['users'].find({}).limit(30).sort([["email", :desc]])
MONGODB yourapp_development['users'].find({}).limit(30).sort([["email", :asc]])

Props to https://github.com/ebeigarts for the patch. It gets you to at least run with the ball for now.


  • Filters are disabled
  • Comments are disabled (I have never used this with ActiveAdmin though)
  • You’ll probably need to disable this once ActiveAdmin closes issue #26 (which you are now watching, right?)
Version Disclosure: This post was valid with ActiveAdmin 0.3.4, Mongoid 2.3.4 and Rails 3.0/3.1