最近正在看 Agile Web Development with Rails,看到 partial template.里面有一段话,看不大明白:
Now that we have a partial for a line item, let’s do the same for the cart. First, we’ll create the _cart.html.erb template. This is basically our carts/show.html.erb template but using cart instead of @cart, and without the notice. (Note that it’s OK for a partial to invoke other partials.)
Download rails32/depot_j/app/views/carts/_cart.html.erb
<div class="cart_title">Your Cart</div>
<table>
➤ <%= render(cart.line_items) %>
<tr class="total_line">
<td colspan="2">Total</td>
➤ <td class="total_cell"><%= number_to_currency(cart.total_price) %></td>
</tr>
</table>
➤ <%= button_to 'Empty cart', cart, method: :delete,
confirm: 'Are you sure?' %>
这里为什么要用 cart 替代 @cart? 谢谢