Agile Web Development with Rails, Edition 5

8.6 Playtime 8.4 Iteration C4: Functional Testing

8.5 Iteration C5 - Caching

Turn on caching in development

rails dev:cache
Development mode is now being cached.

cache sections

edit app/views/store/index.html.erb
<% if notice %>
  <aside id="notice"><%= notice %></aside>
<% end %>
 
<h1>Your Pragmatic Catalog</h1>
 
<ul class="catalog">
  <% cache @products do %>
    <% @products.each do |product| %>
      <% cache product do %>
        <li>
          <%= image_tag(product.image_url) %>
          <h2><%= product.title %></h2>
          <p>
            <%= sanitize(product.description) %>
          </p>
          <div class="price">
            <%= number_to_currency(product.price) %>
          </div>
        </li>
      <% end %>
    <% end %>
  <% end %>
</ul>
edit test/fixtures/products.yml
# Read about fixtures at
# http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
 
one:
  title: MyString
  description: MyText
  image_url: lorem.jpg
  price: 9.99
 
two:
  title: MyString
  description: MyText
  image_url: lorem.jpg
  price: 9.99
 
ruby: 
  title:       Programming Ruby 1.9
  description: 
    Ruby is the fastest growing and most exciting dynamic
    language out there.  If you need to get working programs
    delivered fast, you should add Ruby to your toolbox.
  price:       49.50
  image_url:   ruby.jpg 

Turn caching back off

rails dev:cache
Development mode is no longer being cached.

8.6 Playtime 8.4 Iteration C4: Functional Testing