Haml - 显式结束缓存

Haml - End caching explicitly

我有 _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"

如果块在底部,我不需要缓存。如何显式结束缓存 do/end 块?

如果你想在里面有一个非缓存的<td>,缓存整个<tr>是没有意义的。

您可以改为缓存 4 个 <td>

%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"