Based on this:
I want to be able to automatically create a lineitem list containing each item in the Items table for an Order when it is saved to the database.
You can use callbacks to handle this. You don't have to do loops:
class Order < ActiveRecord::Base
before_create :add_lineitems
private
def add_lineitems
# This will associate all items in the items table with the new order.
# It'll automatically add records to the lineitems table.
self.item_ids = Item.pluck(:id)
end
end