ActiveAdmin收集对已过滤数据的操作 [英] ActiveAdmin Collection action on filtered data
问题描述
我在索引页面上有一个自定义的收集操作,我想访问该操作中的过滤数据。我怎样才能做到这一点?我可以自行收集收藏吗?还是过滤器参数?
I have a custom collection action on the index page, and I want to access the filtered data inside that action. How can I do this? Can I get the collection itself? or maybe the filter params?
collection_action :do_something do
# call some async process
redirect_to :action => :index, :notice => "started working!"
end
action_item :only => :index do
link_to('DO WORK', do_something_admin_game_stats_path)
end
推荐答案
您应该通过范围
和 filter
参数作为 link_to
操作,然后在 collection_action
中使用 scoped_collection
。
You should pass the scope
and filter
params as options on your link_to
action, and then use scoped_collection
within your collection_action
.
link_to "DO WORK", do_something_admin_game_stats_path(param.slice(:scope, :filter))
我不确定filter是否是正确的参数键,但是原理应该相同。如果由于某种原因您无法在操作链接中访问 params
,请尝试 controller.params
,或者真是绝望的 controller.send(:params)
。我不确定在我头顶上方的视图中是否可以公开使用这些参数。
I'm not sure if filter is the correct param key, but the principle should be the same. If for some reason you can't access params
in the action link, try controller.params
or if you're really desperate controller.send(:params)
. Off the top of my head I'm not sure if the params are publicly available in views off the top of my head.
这篇关于ActiveAdmin收集对已过滤数据的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!