Agile Web Development with Rails, Edition 4

8.6 Playtime 8.4 Iteration C4: Functional Testing

8.5 Iteration C5 - Caching

Turn on caching in development

edit config/environments/development.rb
  config.action_controller.perform_caching = true

cache sections

edit app/views/store/index.html.erb
<p id="notice"><%= notice %></p>
 
<h1>Your Pragmatic Catalog</h1>
 
<% cache @products do %>
  <% @products.each do |product| %>
    <% cache product do %>
      <div class="entry">
        <%= image_tag(product.image_url) %>
        <h3><%= product.title %></h3>
        <%= sanitize(product.description) %>
        <div class="price_line">
          <span class="price"><%= number_to_currency(product.price) %></span>
        </div>
      </div>
    <% end %>
  <% end %>
<% end %>

Turn caching back off

edit config/environments/development.rb
  config.action_controller.perform_caching = false
rm -f public/assets/*
rm -rf tmp/*cache/*

Restart the server.

8.6 Playtime 8.4 Iteration C4: Functional Testing