我有一个过滤器
#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
谢谢
我有一个过滤器
#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
谢谢
尝试这样的事情:
编辑:我已经根据评论反馈更改了我的代码示例。
编辑:我已更新示例以包含 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')
有时按国名搜索会容易得多:
检查这篇文章:http ://blog.zeratool.net/2012/02/02/activeadmin-filter-from-drop-down-to-textfield/
现在您有了更好的选择,您可以使用AJAX 过滤器!
filter :country, as: :ajax_select, data: { search_fields: [:name] }