I am having a slight problem with appending data and then adding it into the array.
Here is my code
@order.orderdesc ||= [] @cart.line_items.each do |item| @order.orderdesc += item.quantity + "x" + item.product.title end I only want to add item.quantity and item.product.title. They can be accessed.
Thanks
If you want to add "stuff" in an array, the += is not made for that. You can use the << operator (append at the end of the array):
@order.orderdesc ||= [] @cart.line_items.each do |item| @order.orderdesc << item.quantity + "x" + item.product.title end Or you can use .push():
@order.orderdesc ||= [] @cart.line_items.each do |item| @order.orderdesc.push( item.quantity + "x" + item.product.title ) end If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With