I am new to Ruby on Rails and Leaflet, but I am trying to implement a map using the gem 'leaflet-rails' version 1.6 with Rails version 6.0.3.2.
here is a similar thread on a similar issue.
I am receiving 'ReferenceError: L is not defined' when I load up my page.. I have followed the install guide and have been trying to implement the map for the last 2 night now, with no avail. The only way I am able to get the map to work is if I add the code below into the HTML file I am trying to implement the map into.
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"/>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"/>
I have checked and I am Using leaflet-rails 1.6.0
I have added 'gem 'leaflet-rails'' to the Gemfile
I have added '*= require leaflet' to the application.css file
I have added '//= require' leaflet to the application.js file
I have added the code below to application.html.erb
<%= javascript_pack_tag 'application', 'data-turbolinks-track': true %>
<%= stylesheet_link_tag 'application' %>
I have added the code below to the leaflet.rb file I created
' Leaflet.tile_layer = 'http://{s}.tile.cloudmade.com/YOUR-CLOUDMADE-API-KEY/997/256/{z}/{x}/{y}.png'
# You can also use any other tile layer here if you don't want to use Cloudmade - see http://leafletjs.com/reference.html#tilelayer for more
Leaflet.attribution = 'Your attribution statement'
Leaflet.max_zoom = 18'
When I refresh the page and inspect the HTML, the script is running the below code.
var map = L.map('map', {});
map.setView([51.52238797921441, -0.08366235665359283], 18);
L.tileLayer('http://{s}.tile.cloudmade.com/YOUR-CLOUDMADE-API-KEY/997/256/{z}/{x}/{y}.png', {
attribution: 'Your attribution statement',
maxZoom: 18,
}).addTo(map);
If I look inside the head of the file, it seems to be referencing the application.js file, but no where can I see it referencing anything related to Leaflet.
<script src="/packs/js/application-9fe6f817df469889a178.js" data-turbolinks-track="true"></script>
I am pretty lost on what to try next as I am very new to Rails.
I would highly appreciate any help. Regards, Rory.