i have an array of selected product_ids and product quantities i need to insert through active records into the rails database model in a single HTTP request. the orderitem arrays belong to an order_detail active record model. I need to be able to record this items into tghe database on clicking the "submit order" botton from the react client side.
def create
order_detail = @user.order_details.create(order_detail_params)
@order_item = OrderItem.create(order_item_params.merge(order_detail_id: order_detail.id))
if @order_item.valid?
render json: @order_item, status: :created
else
render json: @order_item.errors, status: :unprocessable_entity
end
end
def order_item_params
params.require(:order_item).permit([:quantity, :product_id])
end
def order_detail_params
params.require(:order_detail).permit(:total )
end