8.6 Playtime 8.4 Iteration C4: Functional Testing
Turn on caching in development
rails dev:cache
Development mode is now being cached.
add a method to return the latest product
edit app/models/product.rb
def self.latest
Product.order(:updated_at).last
end
cache sections
edit app/views/store/index.html.erb
<p id="notice"><%= notice %></p>
<h1>Your Pragmatic Catalog</h1>
<% cache ['store', Product.latest] do %>
<% @products.each do |product| %>
<% cache ['entry', 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
rails dev:cache
Development mode is now being cached.