logger.debug("@@@@ - line item count is #{order.line_items.count}")
order.line_items.each_with_index do |line_item, index|
logger.debug("@@@@ - line item")
request.memo += “#{line_item.order_quantity} x
#{line_item.product_name}”
if index < order.line_items.count
request.memo += ', '
end
end
This twice for each line item
order is an activerecord object and line_items is an array of active
record objects
The ouptut from the above looks like this
@@@@ - line item count is 3
@@@@ - line item
@@@@ - line item
@@@@ - line item
@@@@ - line item
@@@@ - line item
@@@@ - line item
and the text in request.memo looks like this
Payment for Order Number 6 for the following items 1 x ff, 1 x ff, 1 x
ggffggff, 1 x ggffggff, 1 x 10, 1 x 10,
So it looks like the loop is iterating twice for each line_item
The count shows there are only three line items and there are only 3
records in the line items table attached to the order.
The same happens with .each as well and the index only ever reaches the
number 3 which is why I commented out the if index check.
I’m guessing that the problem is not with the loop but with the order
object but I can’t think how this could be an issue or what to check
for.