Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 533
tali Avatar asked Oct 02 '22 14:10

tali


1 Answers

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.

like image 91
Josh Kovach Avatar answered Oct 13 '22 11:10

Josh Kovach