2015-03-19 68 views
2

我有一個緩存文件_product.html.haml: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塊可以明確地結束?

回答

3

如果你想在其中有一個非緩存的<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" 
+0

哦,正好!非常感謝你! – 2015-03-19 08:38:18