14

在使用 ActiveAdmin 注册的资源中,我为模型定义了以下 default_scope:

default_scope :order => 'activities.updated_at DESC'

这显然使我无法通过单击列标题来更改资源索引页面上的排序。有没有办法保持这个默认范围但让 Active Admin 排序工作?

4

5 回答 5

46
ActiveAdmin.register Post do
  controller do
    def scoped_collection
      Post.unscoped
    end
  end
end 
于 2012-04-03T17:35:42.020 回答
7
scope('all', default: true) { |scope| scope.where(...) }
于 2017-12-27T10:14:01.343 回答
1

试试这个解决方案。

#/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
于 2013-10-08T11:17:11.693 回答
0
  scope_to do
   Class.new do
    def self.cookies
     Cookie.unscoped
    end
   end
  end

更多信息:http: //blogs.burnsidedigital.com/2012/09/ignoring-default_scope-in​​-activeadmin /

于 2012-09-19T00:22:33.380 回答
-1

您是要确定活动的范围还是仅对它们进行排序,因为此调用仅对它们进行排序,实际上并没有严格地确定查询的范围。

根据我所知道的ActiveAdmin以及他们的文档所述,您可能应该像这样设置它。

  class Activities < ActiveRecord::Base
    default_scope lambda { where :updated_at => true }
  end
于 2012-02-27T21:07:19.813 回答