我正在为表中的每一行使用 render partial: 'fragment', locals:{obj:item}
。
处理整个页面需要很长时间。
有没有办法在第一次加载时保存每个项目的所有片段,而不是在服务器工作期间每次都重新渲染它们?
已更新
card/index.html.haml
%table
=render partial: 'card/card', collection: @cards, cached: true
card/_card.html.haml
-cache card do
%tr=card.title
card_controller.rb
def index
@cards = Card.order(:name)
end
已解决
在我添加到 development.rb 后缓存开始工作:
config.action_controller.perform_caching = true
config.cache_store = :memory_store, { size: 64.megabytes }
最佳答案
或者您可以运行 rails dev:cache
来切换缓存。
关于ruby-on-rails - Rails 如何缓存部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52620379/