我有带有缓存的_product.html.haml文件:
- cache product do
%tr{product_id: "#{product.id}"}
%td.col-md-1.vert-align= image_tag product.image.url(:thumb), class: "img-thumbnail" if product.image?
%td.col-md-4.vert-align= link_to product.title, product
%td.col-md-1.vert-align= number_to_currency product.price
%td.col-md-1.vert-align= product.available ? content_tag(:span, 'Available', class: "available") : content_tag(:span, 'Booked', class: "booked")
- if user_signed_in? && current_user.is_admin
%td.col-md-2.vert-align
= link_to "Edit", edit_product_path(product), class: "btn btn-default btn-xs"
= link_to "Delete", '#', title: "Delete product", class: "btn btn-danger btn-xs delete-product"
如果底部有块,则不需要缓存。缓存的执行/结束块如何显式结束?
<tr>
如果要在<td>
内部缓存非缓存,则缓存整个缓存是没有意义的。
您可以<td>
改为缓存4 s:
%tr{product_id: "#{product.id}"}
- cache product do
%td.col-md-1.vert-align= image_tag product.image.url(:thumb), class: "img-thumbnail" if product.image?
%td.col-md-4.vert-align= link_to product.title, product
%td.col-md-1.vert-align= number_to_currency product.price
%td.col-md-1.vert-align= product.available ? content_tag(:span, 'Available', class: "available") : content_tag(:span, 'Booked', class: "booked")
- if user_signed_in? && current_user.is_admin
%td.col-md-2.vert-align
= link_to "Edit", edit_product_path(product), class: "btn btn-default btn-xs"
= link_to "Delete", '#', title: "Delete product", class: "btn btn-danger btn-xs delete-product"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句