我正在尝试创建一个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