我正在嘗試創建一個collection_action,我將對整個已過濾項目的集合進行一些操作。我的問題是,從collection_action內我似乎沒有訪問過濾收集。當我訪問collection
時,它只是記錄第一頁上的項目。在我的action_item中,我可以訪問collection_before_scope
,這正是我想要的過濾記錄,但是當我嘗試從我的collection_action
中訪問它時,這是空的。ActiveAdmin訪問過濾的集合
下面是我current setup
試圖找到正確的集合。
collection_action :dosmth, :method => :get do
# collection_before_scope will be empty
puts "collection_before_scope = " + collection_before_scope.to_yaml
# collection will return only the filtered items on the front page
puts "collection = " + collection.to_yaml
redirect_to :back, notice: 'Something happening'
end
action_item :only => :index do
# collection_before_scope will return the full collection that I'm looking for.
puts "collection_before_scope = " + collection_before_scope.to_yaml
link_to "Export", dosmth_admin_earned_points_path(controller.params)
end
與最接近相關的問題,我能找到的就是這一點,ActiveAdmin Collection action on filtered data,這似乎並沒有幫助我。
任何幫助將不勝感激。
謝謝
更新:
我仍然有同樣的問題,但我已經想通一些東西。如果我嘗試訪問collection_before_scope
之前的集合,則正確的過濾項目位於collection_before_scope中。我不想爲了得到正確的collection_before_scope
而訪問集合。不知道爲什麼會發生這種情況。
collection_action :dosmth, :method => :get d0
# collection will return only the filtered items on the front page
puts "collection = " + collection.to_yaml
# collection_before_scope will be correct because I accessed the collection first. why???
puts "collection_before_scope = " + collection_before_scope.to_yaml
redirect_to :back, notice: 'Something happening'
end