在使用 ActiveAdmin 注册的资源中,我为模型定义了以下 default_scope:
default_scope :order => 'activities.updated_at DESC'
这显然使我无法通过单击列标题来更改资源索引页面上的排序。有没有办法保持这个默认范围但让 Active Admin 排序工作?
在使用 ActiveAdmin 注册的资源中,我为模型定义了以下 default_scope:
default_scope :order => 'activities.updated_at DESC'
这显然使我无法通过单击列标题来更改资源索引页面上的排序。有没有办法保持这个默认范围但让 Active Admin 排序工作?
ActiveAdmin.register Post do
controller do
def scoped_collection
Post.unscoped
end
end
end
scope('all', default: true) { |scope| scope.where(...) }
试试这个解决方案。
#/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
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 /
您是要确定活动的范围还是仅对它们进行排序,因为此调用仅对它们进行排序,实际上并没有严格地确定查询的范围。
根据我所知道的ActiveAdmin
以及他们的文档所述,您可能应该像这样设置它。
class Activities < ActiveRecord::Base
default_scope lambda { where :updated_at => true }
end