與ActiveAdmin註冊的資源覆蓋default_scope在ActiveAdmin,我已經爲模型定義如下default_scope:如何在Rails的
default_scope :order => 'activities.updated_at DESC'
這顯然是防止我能夠改變對資源的索引排序通過點擊列標題頁面。有沒有辦法保持這個默認範圍,但獲得活動管理排序工作?
與ActiveAdmin註冊的資源覆蓋default_scope在ActiveAdmin,我已經爲模型定義如下default_scope:如何在Rails的
default_scope :order => 'activities.updated_at DESC'
這顯然是防止我能夠改變對資源的索引排序通過點擊列標題頁面。有沒有辦法保持這個默認範圍,但獲得活動管理排序工作?
您是試圖限制活動的範圍還是僅僅對它們進行排序,因爲此調用僅對它們進行排序,而不是實際上以最嚴格的思路對範圍進行查詢。
從我所知道的ActiveAdmin
以及他們的文檔所指出的,你應該像這樣設置它。
class Activities < ActiveRecord::Base
default_scope lambda { where :updated_at => true }
end
ActiveAdmin.register Post do
controller do
def scoped_collection
Post.unscoped
end
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/
嘗試這個解決方案。
#/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('all', default: true) { |scope| scope.where(...) }