ruby-on-rails – ActiveAdmin Access过滤集合
我正在尝试创建一个collection_action,我将在整个过滤项集合中执行某些操作.我的问题是,在collection_action中,我似乎无法访问过滤的集合.当我访问集合时,它只是记录第一页上的项目.在我的action_item中,我可以访问collection_before_scope,这正是我想要的过滤记录,但当我尝试从我的collection_action中访问它时,这是空的.
以下是我目前的设置,试图找到正确的集合. 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 解决方法
试试这个:
put“filtered collection =”apply_filtering(collection).to_yaml(在调用collection之前) 在您首先访问集合后,为什么要到达正确的过滤集合? collection方法将调用find_collection方法:https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/resource_controller/data_access.rb#L32 find_collection方法将调用apply_filter方法:https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/resource_controller/data_access.rb#L50 一旦调用了收集方法: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |