RailsCasts Pro episodes are now free!
Learn more or hide this
<% title "Shopping Cart" %> <table id="line_items"> <tr> <th>Product</th> <th>Qty</th> <th class="price">Unit Price</th> <th class="price">Full Price</th> </tr> <%= render :partial => 'line_item', :collection => @cart.line_items %> <tr> <td class="total price" colspan="4"> Total: <%= number_to_currency @cart.total_price %> </td> </tr> </table>
<tr class="<%= cycle :odd, :even %>"> <td><%=h line_item.product.name %></td> <td class="qty"><%= line_item.quantity %></td> <td class="price"><%= free_when_zero(line_item.unit_price) %></td> <td class="price"><%= free_when_zero(line_item.full_price) %></td> </tr>
def full_price unit_price*quantity end
def total_price line_items.to_a.sum(&:full_price) end
def free_when_zero(price) price.zero? ? "FREE" : number_to_currency(price) end