Tuesday, February 21, 2012

[Rails] Re: nil can't be coerced into BigDecimal

>> nil can't be coerced into BigDecimal
>>
>> def total_price
>> line_items.to_a.sum { |item| item.total_price }
>> end
>> model/cart.rb
>>
>
> That error would be expected when some of line_items.total_price returns
> nil. Moreover you can sum total prices without .to_a, that would be more
> efficient.
tried to applying this but gotting the problem in the view
>
>> def total_price
>> product.price * quantity
>> end
>>
>> def total_price
>> if product.price
>> product.price * quantity
>> else
>> product.price = "0.0".to_d
> It is not necessary to write attribute :price, just let it return
> zero. 0.to_d in this case.
i tried this and it worked out but when reseting the cart it return the
error
>> end
>> end
> Now. before test it again, check in the database if any product has a
> nil or any non-bigdecimal value.

this is being weird when i tried your suggestion it worked out but when
i
clear delete the cart again it return to the error :(

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate