Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override default_scope in ActiveAdmin in Rails

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?

like image 259
John Avatar asked Feb 27 '12 20:02

John


3 Answers

ActiveAdmin.register Post do
  controller do
    def scoped_collection
      Post.unscoped
    end
  end
end 
like image 197
patrick Avatar answered Oct 30 '22 15:10

patrick


scope('all', default: true) { |scope| scope.where(...) }
like image 29
Ziv Barber Avatar answered Oct 30 '22 15:10

Ziv Barber


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
like image 1
Nadeem Yasin Avatar answered Oct 30 '22 13:10

Nadeem Yasin