Using RoR 4.1.4
I am trying to use the leaflet-rails gem. I followed the steps outlined in the github page, but when I try to load the map, I see
ReferenceError: L is not defined
in the browser console. This obviously means that the helper from the gem is being loaded and executed but it can't find the leaflet.js
file.
However, the head section of the page shows that /assets/leaflet.js
is being referenced and it actually IS there.
When I look at the generated code:
<div id="map"></div>
<script>
var map = L.map('map')
map.setView([-54.0, 6.08], 16)
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
maxZoom: 18,
subdomains: '',
}).addTo(map)
</script>
</div>
<script src="/assets/jquery.js?body=1" data-turbolinks-track="true"></script>
<!-- all the other scripts loaded -->
<script src="/assets/exif.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/leaflet.js?body=1" data-turbolinks-track="true"></script>
<!-- some more scripts -->
So the gem adds a script right below the map div, and only then, due to the sprockets mechanism and all that, the other scripts are loaded. To me this looks like then obviously the script can't possibly load the leaflet.js as it's being referenced afterwards!
So...am I misunderstanding something re how RoR handles gems and javascripts? It must have been working at some point...
Here's my /app/assets/javascript/application.js:
//= require jquery
//= require jquery.ui.widget
// Here I load a whole bunch of javascripts which are related to jquery-fileupload, cut for brevity
//= require bootstrap.min
//= require bootbox.min
//= require bootstrap-datepicker
//= require exif
//= require leaflet
//= require turbolinks
//= require_tree .