我有一個過濾器activeadmin:緩存過濾值
#in cities.rb
filter :country #drop-down select list with more than 200 values
它幾乎靜態列表,我需要它緩存,以提高生產率
我已經試過
謝謝
我有一個過濾器activeadmin:緩存過濾值
#in cities.rb
filter :country #drop-down select list with more than 200 values
它幾乎靜態列表,我需要它緩存,以提高生產率
我已經試過
謝謝
嘗試類似這樣:
編輯:我根據評論反饋更改了我的代碼示例。
編輯:我已經更新了示例以包含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 filters!
filter :country, as: :ajax_select, data: { search_fields: [:name] }
我需要緩存整個HTML選擇沒有集合對象以供日後選擇渲染..在你的邏輯,我可以創造像'市:: COUNTRIES = [「阿根廷」,「伯利茲」,...] '並使用它 - 這不是我的情況..我需要緩存所有的可能性:到期,在開發環境中禁用等等.. – okliv 2013-03-21 12:00:10
啊,這是多一點涉及。特別是即將到期的部分。 我建議尋找['Rails.cache.fetch'](http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-fetch) 哦,我會嘗試編輯我的答案。 – 2013-03-22 00:08:52