Привет, ребята, я играю с RoR в окружении рельсов. 3 ruby 1.9
я застрял в
ноль не может быть приведен в BigDecimal
ошибка
мне нужно получить общую стоимость продуктов внутри корзины
я знаю, где проблема (я думаю), но я почти все сделал
корзина / show.html.rb
<div class="cart_title" >Your Cart</div>
<table>
<% for item in @cart.line_items %>
<tr>
<td><%= item.quantity %>×</td>
<td><%= item.product.title %></td>
<td class="item_price" ><%= number_to_currency(item.total_price) %></td>
</tr>
<% end %>
<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?' %>
модель / line_item.rb
def total_price
line_items.to_a.sum { |item| item.total_price }
end
модель / cart.rb
def total_price
product.price * quantity
end
мой второй вариант
def total_price
if product.price
product.price * quantity
else
product.price = "0.0".to_d
end
end
но все равно это не сработает
спасибо больше силы нам!