gpt4 book ai didi

ruby-on-rails - activeadmin:缓存过滤器值

转载 作者:行者123 更新时间:2023-12-04 12:55:12 24 4
gpt4 key购买 nike

我有一个过滤器

#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')

关于ruby-on-rails - activeadmin:缓存过滤器值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15342429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com