【发布时间】:2016-04-29 09:23:12
【问题描述】:
我想我一定错过了 Collection caching - 1.3.1 的工作原理。当我将cached: true 属性添加到渲染时,它不会在模型更改时刷新缓存。但是,如果没有此属性,它将按预期工作。
attending.html.erb
<%= render partial: 'attending_item', collection: @attendees, locals: {reserved: true}, cached: true %>
_item_attending.html.erb
<% cache([attendee.user, attendee, reserved]) do %>
<li class="attendee_id_<%= attendee.id %> <%= reserved ? 'reserved' : 'confirmed' %>">
<%= image_tag(attendee.user.profile.avatar_url(:avatar), size: '25x25') %>
<%= attendee.user.full_name %>
</li>
<% end %>
user 模型将通过 Profile 模型上的 touch: true 更新,因此当他们更新头像时:
belongs_to :user, touch: true
有人可以向我解释一下我缺少什么或不了解集合缓存是如何工作的,也许这是 Rails 中的错误?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-5