ActiveAdmin Collection action on filtered data

江枫思渺然 提交于 2019-12-22 11:22:30

问题


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

回答1:


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))

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.



来源:https://stackoverflow.com/questions/21756136/activeadmin-collection-action-on-filtered-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!