It's time for my application to transition into production mode, and I have come to the realization that some of the code in development mode needs a major overhaul. Particularly, the views where I embedded data iteratively into Google Charts API Javascript code to create maps overlaid with data.
This is the existing code:
<h1>US Map of Startup Density</h1>
<% i = 0 %>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawMarkersMap);
function drawMarkersMap() {
var data = google.visualization.arrayToDataTable([
['Location', 'Startups'],
<% @locations.count.times do %>
[<%= "'#{@locations[i].name}', #{@locations[i].d_s}" %>],
<% i += 1 ;end %>
]);
var options = {
region: 'US',
resolution: 'provinces',
displayMode: 'markers',
magnifyingGlass: {enable: true, zoomFactor: 9.0},
colorAxis: {colors: ['green', 'blue']}
};
var chart = new google.visualization.GeoChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
</script>
</head>
<body>
<h4>All cities with less than 10 startups have been exempted from this graph.</h4>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
Upon inspection, it's clear that I made the mistake of directly embedding Ruby into JavaScript, which surprisingly worked initially but now poses a challenge for serving this map effectively to users in production mode.
I am exploring different solutions:
- Considering using the gon gem but unsure about its compatibility with the current complexity of the code.
- Exploring the possibility of processing the data in JavaScript, although my knowledge in this area is limited, especially when dealing with an ActiveRecord call.
- Tried disabling the JavaScript asset compiling in 'production.rb', but encountered difficulties. It's possible that I implemented it incorrectly.