edwardmp
edwardmp

Reputation: 6611

Wrong partial is rendered in Rails in some cases, possible fragment caching issue

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.

Upvotes: 8

Views: 281

Answers (0)

Related Questions