guhurak
guhurak

Reputation: 139

How do deal with Collection caching and i18n?

I am trying to internationalize my Rails app. I dont know how do deal with Collection caching.

I know that we can do this for one active record object :

<% cache([I18n.locale, product]) do %>
  <!-- here the markup for a single product -->
  <%= render partial:'products/product', locals: { product: product } %>
<% end %>

But how to do it for collection caching? :

<%= render partial: 'products/product', collection: @products, as: :product, cached: true %>

Thanks for your incoming help

Upvotes: 2

Views: 685

Answers (1)

Nicolas Maloeuvre
Nicolas Maloeuvre

Reputation: 3169

You can use this :

<%= render partial: 'products/product', collection: @products, as: :product, cached: -> product { [I18n.locale, product] } %>

Upvotes: 1

Related Questions