2012-02-27 24 views
8

與ActiveAdmin註冊的資源覆蓋default_scope在ActiveAdmin,我已經爲模型定義如下default_scope:如何在Rails的

default_scope :order => 'activities.updated_at DESC' 

這顯然是防止我能夠改變對資源的索引排序通過點擊列標題頁面。有沒有辦法保持這個默認範圍,但獲得活動管理排序工作?

回答

0

您是試圖限制活動的範圍還是僅僅對它們進行排序,因爲此調用僅對它們進行排序,而不是實際上以最嚴格的思路對範圍進行查詢。

從我所知道的ActiveAdmin以及他們的文檔所指出的,你應該像這樣設置它。

class Activities < ActiveRecord::Base 
    default_scope lambda { where :updated_at => true } 
    end 
33
ActiveAdmin.register Post do 
    controller do 
    def scoped_collection 
     Post.unscoped 
    end 
    end 
end 
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 
1
scope('all', default: true) { |scope| scope.where(...) }