small medium large xlarge

Generic-user-small
25 Sep 2012, 05:18
Ron Stiles (1 post)

Hello all,

I am currently working on on pg. 128 (PDF 4th ed. P3).

After changing li elements to the table, I’m getting a Private method error.

Previous Code

<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>

<h2>Your Pragmatic Cart</h2>
<ul>    
  <% @cart.line_items.each do |item| %>
    <li><%= item.quantity %> &times; <%= item.product.title %></li>
  <% end %>
</ul>
<!-- START_HIGHLIGHT -->
<%= button_to 'Empty cart', @cart, method: :delete,
    data: { confirm: 'Are you sure?' } %>
<!-- END_HIGHLIGHT -->

New code

<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>

<!-- START_HIGHLIGHT -->
<h2>Your Cart</h2>
<table>
<!-- END_HIGHLIGHT -->
  <% @cart.line_items.each do |item| %>
<!-- START_HIGHLIGHT -->
    <tr>
      <td><%= item.quantity %>&times;</td>
      <td><%= item.product.title %></td>
      <td class="item_price"><%= number_to_currency(item.total_price) %></td>
    </tr>
<!-- END_HIGHLIGHT -->
  <% end %>
<!-- START_HIGHLIGHT -->
  <tr class="total_line">
    <td colspan="2">Total</td>
    <td class="total_cell"><%= number_to_currency(@cart.total_price) %></td>
  </tr>
<!-- END_HIGHLIGHT -->
<!-- START_HIGHLIGHT -->
</table>
<!-- END_HIGHLIGHT -->

<%= button_to 'Empty cart', @cart, method: :delete,
    data: { confirm: 'Are you sure?' } %>

Error

private method `total_price' called for #<LineItem

After researching this for a couple of hours I have not been able to find a solution.

While troubleshooting, I have this line of code to be causing the problem, but I don’t see any private associations with it.

<td class="item_price"><%= number_to_currency(item.total_price) %></td>

Thanks again for your help.

Generic-user-small
10 Dec 2014, 22:42
richard martin (1 post)

I am having exactly the same problem but notice that there was no comment or resolution.

Can anyone suggest what is happening?

You must be logged in to comment