Rails ActiveAdmin member_action links and maintaining sort and filter options
I'm using ActiveAdmin for the first time on a project and I've added some member action links for changing a position attribute (up, down, bottom, top) on a model with acts_as_list (move_higher, move_lower, ...).
The first release did the trick, and allowed positions to easily be managed, but an early complaint was that sort and filter options on the index list weren't being maintained when those position links were clicked. Someone might have sorted by position, and used a filter or two to get a list of items, and when they used these member action position links their filters and sorting were removed when they were redirected back to the index page.
To solve this I simply passed the params hash along to the member_action path, e.g.:
move_up_admin_promotion_path(promotion, params)
And then passed the sort and filter params along in the member action's redirect, e.g.:
member_action :move_up, :method => :put do promotion = Promotion.find(params[:id]) promotion.move_higher redirect_to :action => :index, :order => params[:order], :q => params[:q] end
Problem solved, position links now redirect back to the index with the original sort and filters intact.