skadoosh
skadoosh

Reputation: 481

View caching in rails with parameters

Is there a way where I could cache views and have the option to send it parameters.

e.g.

<% Product.all.each do |p| %>
  All available products:
  <% cache('product_'+p.name) do %>
    <div >
      <div><%= p.x %></div>
      <div><%= link_to p.name, product_url(p) %></div>
      ....
      ....
    </div>
  <% end %>
<% end %>

In this case, is there a way where i can cache the markup and send the product as parameter? The requirement is such that 'p.x' may vary every time, and if i cache the view, it will not display the new 'p.x' value.

Upvotes: 0

Views: 88

Answers (1)

techvineet
techvineet

Reputation: 5111

No, you cannot send the parameters to cached content. We use caching to serve the content which is less dynamic or does not change too often. So, in your case its better keep the block out of caching.

Upvotes: 1

Related Questions