activeadmin:缓存过滤器值

时间:2013-03-11 15:29:07

标签: ruby-on-rails activeadmin

我有一个过滤器

#in cities.rb

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

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

我试过

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

谢谢

3 个答案:

答案 0 :(得分: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')

答案 1 :(得分:0)

有时按国家/地区名称搜索可能会容易得多:

查看此文章:http://blog.zeratool.net/2012/02/02/activeadmin-filter-from-drop-down-to-textfield/

答案 2 :(得分:0)

现在您有了更好的选择,您可以使用AJAX filters

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