Search code examples
ruby-on-railscachingrails-i18n

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


Solution

  • You can use this :

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