# nil can't be coerced into BigDecimal Options

**URL:** <https://discuss.rubyonrails.org/t/nil-cant-be-coerced-into-bigdecimal-options/62916>\
**Category:** rubyonrails-talk\
**Created:** [February 21, 2012, 7:18am UTC](https://discuss.rubyonrails.org/t/nil-cant-be-coerced-into-bigdecimal-options/62916 "2012-02-21T07:18:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [February 21, 2012, 7:18am UTC](https://discuss.rubyonrails.org/t/nil-cant-be-coerced-into-bigdecimal-options/62916/1 "2012-02-21T07:18:51Z")

</div>

hi guys im playing with RoR with the environment of rails 3 ruby 1.9 i got stuck in nil can't be coerced into BigDecimal error i need to get the total cost of the products inside the cart i know where the problem is(i think) but i almost did every thing cart/show.html.rb \<div class="cart\_title" \>Your Cart\</div\> &nbsp;&nbsp;&nbsp;&nbsp;\<table\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% for item in @cart.line\_items %\> &nbsp;&nbsp;&nbsp;&nbsp;\<tr\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= item.quantity %\>&times;\</td\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<td\>\<%= item.product.title %\>\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\<td class="item\_price" \>\<%= number\_to\_currency(item.total\_price) %\>\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\</tr\> &nbsp;&nbsp;&nbsp;&nbsp;\<% end %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<tr class="total\_line" \> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<td colspan="2" \>Total\</td\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<td class="total\_cell" \>\<%= number\_to\_currency(@cart.total\_price) %\>\</td\> &nbsp;&nbsp;&nbsp;&nbsp;\</tr\> &nbsp;&nbsp;&nbsp;&nbsp;\</table\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= button\_to 'Empty cart', @cart, :method =\> :delete, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:confirm =\> 'Are you sure?' %\> model/line\_item.rb &nbsp;&nbsp;def total\_price &nbsp;&nbsp;&nbsp;&nbsp;line\_items.to\_a.sum { |item| item.total\_price } &nbsp;&nbsp;end model/cart.rb def total\_price &nbsp;&nbsp;&nbsp;&nbsp;product.price \* quantity &nbsp;&nbsp;end my second option is def total\_price &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if product.price &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;product.price \* quantity &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;product.price = "0.0".to\_d &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;end but still this wont work thanks more power to us!
