I didn't see you code completely, but
line_items.to_a.sum { |item| item.total_price }
How can it count correct if only ONE item in the cart? :)
Obviously, if you want to get Array, use Array.wrap method like this:
Array.wrap(line_items).sum { |item| item.total_price }
On 21.02.2012, at 13:21, ruby LED wrote:
> i tried refactoring my destroy method now its working fine but my second
> issue is when i add item to the cart at first attemp it returns to that
> error again but returning to the product list it worked fine im just
> wondering if my add_product is code is ok?
>
> def add_product(product_id)
> current_item = line_items.where(:product_id => product_id).first
>
> if current_item
> current_item.quantity = current_item.quantity.to_i + 1
> else
> current_item = LineItem.new(:product_id=>product_id)
> line_items << current_item
> end
> current_item
> end
>
>
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.