Make ActiveAdmin and Mongoid Friends Rails 3.2

I am working on an app where I wanted to use ActiveAdmin. The
interesting part is we are using Mongo for the database and chose
Mongoid as the ORM. At this time ActiveAdmin is not natively ORM agnostic. I found this Github Repository demonstrates the necessary patching needed to allow ActiveAdmin and Mongoid to coexist and work cohesively to deliver an admin interface. The critical change is the patch in initializers. Depending on your configuration though you may also need to make some tweaks in app/admin.

In order to maintain compatibility with our hosting environment as well as keep the app fresh and up to date, we put the app on Rack 1.4.1 and Rails
3.2.x. This required upgrading meta_search gem and ActiveAdmin gem.
Afterwards some of the patching that had been done started whipping
nasty errors around.

superclass mismatch for class ResourceController (TypeError)

Here is the relevant code where the exception is originating from.

module ActiveAdmin
  class Namespace
    # Disable comments
    def comments?
      false
    end
  end

  class Resource
    def resource_table_name
      resource.collection_name
    end

    # Disable filters
    def add_default_sidebar_sections
    end
  end

  class ResourceController < ::InheritedResources::Base
    # Use #desc and #asc for sorting.
    def sort_order(chain)
      params[:order] ||= active_admin_config.sort_order
      table_name = active_admin_config.resource_table_name
      if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
        chain.send($2, $1)
      else
        chain # just return the chain
      end
    end

    # Disable filters
    def search(chain)
      chain
    end
  end
end

Fixing our little dilemma is really quite simple, our superclass exception is occurring because we are re-opening the ActiveAdmin::ResourceController class, but the original one as it is defined does not inherit from ::InheritedResources::Base (anymore) instead it now inherits from ActiveAdmin::Base. So lets fix that.

module ActiveAdmin
  class Namespace
    # Disable comments
    def comments?
      false
    end
  end

  class Resource
    def resource_table_name
      resource.collection_name
    end

    # Disable filters
    def add_default_sidebar_sections
    end
  end

  class ResourceController < ActiveAdmin::BaseController
    # Use #desc and #asc for sorting.
    def sort_order(chain)
      params[:order] ||= active_admin_config.sort_order
      table_name = active_admin_config.resource_table_name
      if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
        chain.send($2, $1)
      else
        chain # just return the chain
      end
    end

    # Disable filters
    def search(chain)
      chain
    end
  end
end

Great now everyone is happy!

 
2
Kudos
 
2
Kudos

Now read this

Minimum MySQL Privileges for Rails

Every time I go to setup a dedicated user in a MySQL database server to support a Rails application I find myself searching the web for the privileges that Rails needs. By the way, if you are hooking to a MySQL database in your Rails... Continue →