I have a template that displays a list of events
<tbody>
<%= render partial: 'event', collection: events, cached: true %>
</tbody>
The partial event
:
<% cache event do %>
<tr>
<td>
Something
</td>
<td>
<%= render 'identifiable_link_with_tag', identifiable: event.identifiable %>
</td>
</tr>
<% end %>
The partial identifiable_link_with_tag
:
<% cache identifiable do %>
<span class="badge badge-info"><%= identifiable.type %></span> <%= link_to identifiable.identifier, identifiable %>
<% end %>
Now, the odd thing is what follows. Sometimes I notice in the events view that for some events another partial (identifiable
) is rendered instead of identifiable_link_with_tag
: _identifiable
. This seems very odd, and on a page that lists 25 events, this would only happen for 1 or 2 or 3 (or 0) events.
So in short, it seems that sometimes the wrong identifiable is rendered. I do use Rails fragment caching, so that may be a factor. Am I missing something or have I encountered a Rails bug? This issue is very hard to reproduce in development, thus hard to debug.
event
partial oridentifiable_link_with_tag
? What exactly is wrong? One thing with Russian doll caching is that update to anyidentifiable
will not expire theevent
partial it is nested in unless that event istouched
. Not sure if that's the problem you're facing. – Semidiurnalidentifiable_link_with_tag
, the partial foridentifiable
itself is rendered (see updated answer) – Amandaamandiidentifiable
? Maybe that is using the same cache key as the correspondingidentifiable_link_with_tag
, if you're also doingcache identifiable
there too? If so you can try using a custom cache key for one of them. – Semidiurnalidentifiable
partial! I was thinking of some kind of cache key collision too, but if so is this a bug in Rails or not? – Amandaamandiidentifiable_link_with_tag
andidentifiable
partials. This will probably help with debugging. – Mcshane