Skip to content

Instantly share code, notes, and snippets.

View tinynumbers's full-sized avatar

David Daniell tinynumbers

View GitHub Profile
@tinynumbers
tinynumbers / gist:2895643
Created June 8, 2012 13:35
Stack trace when saving a comment on a nested resource in ActiveAdmin 0.4.4
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'
@tinynumbers
tinynumbers / active_admin.rb
Last active December 22, 2019 08:00
ActiveAdmin controller extension to persist resource index filters between requests.
# 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

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.

Usage