javascript - ruby on rails: leaflet-rails not loading -
using ror 4.1.4
i trying use leaflet-rails gem. followed steps outlined in github page, when try load map, see
referenceerror: l not defined
in browser console. means helper gem being loaded , executed can't find leaflet.js
file.
however, head section of page shows /assets/leaflet.js
being referenced , there.
when @ 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> <!-- 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> <!-- more scripts -->
so gem adds script right below map div, , then, due sprockets mechanism , that, other scripts loaded. me looks script can't possibly load leaflet.js it's being referenced afterwards!
so...am misunderstanding re how ror handles gems , javascripts? must have been working @ point...
here's /app/assets/javascript/application.js:
//= require jquery //= require jquery.ui.widget // here load whole bunch of javascripts related jquery-fileupload, cut brevity //= require bootstrap.min //= require bootbox.min //= require bootstrap-datepicker //= require exif //= require leaflet //= require turbolinks //= require_tree .
turns out maybe ror specific issue.
many sites recommend put
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
line loads javascripts, @ end of file, in order speed page display. leaflet-rails
gem, isn't great, , generate problem described above. if putting same line in <head>
section, problem goes away...
p.s. still have problems gem though,
error: no value provided variable {s}
if substitute "http://{s}.tile.osm.org/{z}/{x}/{y}.png
" "http://a.tile.osm.org/{z}/{x}/{y}.png"
works...don't think it's meant work way though...but that's different issue...
Comments
Post a Comment