How to override default_scope in ActiveAdmin in Rails

John picture John · Feb 27, 2012 · Viewed 10.1k times · Source

In a resource registered with ActiveAdmin, I have the following default_scope defined for the model:

default_scope :order => 'activities.updated_at DESC'

This apparently prevents me from being able to change the sorting on the resource's index page by clicking on the column titles. Is there a way to keep this default scope but get Active Admin sorting to work?

Answer

patrick picture patrick · Apr 3, 2012
ActiveAdmin.register Post do
  controller do
    def scoped_collection
      Post.unscoped
    end
  end
end