title: Google Map Javascript API doesn't show InfoWindows in Ruby loop
body: <p>I'm looping through a list of sport camps and plot a marker on a Google Map for each camp. This works for me. However, when I click the marker to see the InfoWindow for each camp it only opens up on the first camp - it doesn't show when I click on any of the other markers.</p>
  
  <p>Do you see what's wrong?</p>
  
  <p>Javascript:</p>
  
  <pre><code>&lt;script&gt;
      function initMap() {
              var start = {lat: 43.3520209, lng: 9.9078704};
  
              var map = new google.maps.Map(document.getElementById('map'), {
                  zoom: 3,
                  center: start,
                  scrollwheel: false
              });
  
              &lt;% @camps.each do |camp| %&gt;
              var &lt;%= camp.city %&gt; = {lat: &lt;%= camp.longitude %&gt;, lng: &lt;%= camp.latitude %&gt;};
  
              var contentString = '&lt;%= link_to camp.name, camp.url, target: "_blank" %&gt;'
  
              var infowindow = new google.maps.InfoWindow({
                  content: contentString,
                  maxWidth: 200,
                  maxHeight: 200
              });
  
              var marker = new google.maps.Marker({
                  position: &lt;%= camp.city %&gt;,
                  map: map
              });
  
              &lt;% end %&gt;
  
              marker.addListener('click', function() {
                      infowindow.open(map, marker);
                    });
      }
    &lt;/script&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/JwnBN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JwnBN.png" alt="enter image description here"></a></p>