Skip to content

Instantly share code, notes, and snippets.


David Daniell tinynumbers

View GitHub Profile

Saving ActiveAdmin filters between requests

This shows one technique for preserving filters on index pages for ActiveAdmin resources, without having to patch the ActiveAdmin core.

It restores any previously-used filters whenever the index page is rendered for a resource, unless the current request is an actual application of new filters. It also properly handles the clear-filters button (via a synchronous Ajax request that happens immediately before the normal filter form processing).

Yes, it's a bit of a hack, but it has worked well for me so far.


tinynumbers / active_admin.rb
Last active Dec 22, 2019
ActiveAdmin controller extension to persist resource index filters between requests.
View active_admin.rb
# this stuff goes in config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
# ...
# put these lines in the "Controller Filters" section of the ActiveAdmin.setup block
# These two are defined in ActiveAdmin::FilterSaver::Controller, which is loaded below.
config.before_filter :restore_search_filters
tinynumbers / gist:2895643
Created Jun 8, 2012
Stack trace when saving a comment on a nested resource in ActiveAdmin 0.4.4
View gist:2895643
activeadmin (0.4.4) lib/active_admin/comments.rb:47:in `send'
activeadmin (0.4.4) lib/active_admin/comments.rb:47:in `_callback_before_185'
activesupport (3.0.11) lib/active_support/callbacks.rb:457:in `_run__1312402412__process_action__453433196__callbacks'
activesupport (3.0.11) lib/active_support/callbacks.rb:410:in `send'
activesupport (3.0.11) lib/active_support/callbacks.rb:410:in `_run_process_action_callbacks'
activesupport (3.0.11) lib/active_support/callbacks.rb:94:in `send'
activesupport (3.0.11) lib/active_support/callbacks.rb:94:in `run_callbacks'
actionpack (3.0.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.11) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.11) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
You can’t perform that action at this time.