Activeadmin: cache filter values

I have a filter

#in cities.rb filter :country #drop-down select list with more than 200 values 

This is an almost static list, I need to cache it for better performance.

I tried

 filter :country, :collection=>proc{cache {options_from_collection_for_select(Country.all, :id, :name)}} #no luck 

thanks

+7
source share
3 answers

Try something like this:

EDIT . I modified my code samples based on comments.

EDIT : I updated the sample to enable html generation.

 # In activeadmin filter :country, :collection => proc do Rails.cache.fetch('countries_for_select') do options_from_collection_for_select(Country.all, :id, :name)} end end # Somewhere, when you want to expire the cache Rails.cache.delete('countries_for_select') 
+1
source

sometimes searching by country name can be a lot easier:

check this article: http://blog.zeratool.net/2012/02/02/activeadmin-filter-from-drop-down-to-textfield/

0
source

Now you have a better option, you can use AJAX filters !

 filter :country, as: :ajax_select, data: { search_fields: [:name] } 
0
source

All Articles