我正在按照《Rails 4 敏捷Web开发指南》的指引进行学习,现在遇到了一个关于缓存的章节。以下是需要遵循的步骤:
in config/environments/development.rb
config.action_controller.perform_caching = true
In app/models/product.rb
def self.latest Product.order(:updated_at).last end
in views/store/index.html.erb
<% 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 %>
然而,当我尝试在缓存块内的代码中添加“Hello”字符串时,它会出现在页面上。我已经进行了所有服务器重启等操作。
但是,当我在本地主机上重新加载页面时,我确实看到了这行文字。
Cache digest for app/views/store/index.html.erb: 6c620ede1d4e824439a7b0e3b177620f
当我设置config.action_controller.perform_caching = false时,它不存在。
GitHub代码库链接:https://github.com/BrianLobdell/depot
谢谢, Brian