Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

activeadmin: cache filter values

I have a filter

#in cities.rb

  filter :country #drop-down select list with more than 200 values

It almost static list, i need to cache it for better productivity

I've tried

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

Thank you

like image 279
okliv Avatar asked Mar 11 '13 15:03

okliv


1 Answers

Try something like this:

EDIT: I've changed my code samples based on comment feedback.

EDIT: I've update the sample to include 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')
like image 104
Amiel Martin Avatar answered Oct 04 '22 00:10

Amiel Martin