ActiveAdmin收集对已过滤数据的操作 [英] ActiveAdmin Collection action on filtered data

查看:70
本文介绍了ActiveAdmin收集对已过滤数据的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在索引页面上有一个自定义的收集操作,我想访问该操作中的过滤数据。我怎样才能做到这一点?我可以自行收集收藏吗?还是过滤器参数?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆