activeadmin:缓存过滤器值

okl*_*liv 7 ruby-on-rails activeadmin

我有一个过滤器

#in cities.rb

  filter :country #drop-down select list with more than 200 values
Run Code Online (Sandbox Code Playgroud)

它几乎是静态列表,我需要缓存它以提高生产力

我试过了

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

谢谢

Ami*_*tin 1

尝试这样的事情:

编辑:我根据评论反馈更改了我的代码示例。

编辑:我已经更新了示例以包括 html 生成。

# 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')
Run Code Online (Sandbox Code Playgroud)