14

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?

John
  • 13,125
  • 14
  • 52
  • 73

5 Answers5

46
ActiveAdmin.register Post do
  controller do
    def scoped_collection
      Post.unscoped
    end
  end
end 
patrick
  • 9,290
  • 13
  • 61
  • 112
7
scope('all', default: true) { |scope| scope.where(...) }
Ziv Barber
  • 595
  • 9
  • 13
1

Try out this solution.

#/admin/user.rb
controller do
  # for index page
  def active_admin_collection
    User.unscoped { super }
  end

  # for show, edit
  def resource
    User.unscoped { super }
  end
end
Nadeem Yasin
  • 4,493
  • 3
  • 32
  • 41
0
  scope_to do
   Class.new do
    def self.cookies
     Cookie.unscoped
    end
   end
  end

more here: http://blogs.burnsidedigital.com/2012/09/ignoring-default_scope-in-activeadmin/

okliv
  • 3,909
  • 30
  • 47
-1

Are you trying to scope the activities or just order them, because this call only orders them, it is not actually scoping the query in the strictest idea.

From what I know of ActiveAdmin and from what their documentation states, you should probably set it up like this.

  class Activities < ActiveRecord::Base
    default_scope lambda { where :updated_at => true }
  end
Justin Herrick
  • 2,981
  • 17
  • 18