1

I'm stumped here, and wondering if anybody can help point me in the correct direction. For that matter, I'm wondering if anybody has ever bumped into this?

When I enter my url in manually the map loads just fine(http://localhost:3000/page/map), but when I create a link in rails the map does load <%= link_to "Map", page_map_path %> or eve <%= link_to "Map", "http://localhost:3000/page/map" %> the page loads, but doesn't show the map until I manually do a refresh.

Here's a link to the repo on bitbucket.

From my testing this happens if I use a gem (either ver 1.0, or 0.7), or load leaflet directly.

2

I have had the same problem. After seeing this, I decided to try some things. It seems that removing the line:

//= require turbolinks

from application.js fixes it for me, with rails 5. I'm not sure as to the root cause as I'm not familiar with turbolinks, and without root cause analysis I wouldn't want to just remove a dependency that rails introduces by default.

  • @cs I think you may be onto something. A brief look into Turbolinks leads me to believe that it speeds up Rails by creating an AJAX call rather than a full page reload when you click on a link. I'm no expert, but this would fit with what we both have been experiencing. For now, I'm willing to forgo the speed increase of Turbolinks to get Leaflet to load. It looks likes adding data: {turbolinks: false} to your link_to turns it off for that page. There were some more complicated DOM oriented calls, but I'll leave that until I better understand coffeescript. – Ben Nov 18 '16 at 22:56
0

I think turbolinks causes some variables to stick around and can problems. I kept getting errors about map already being defined or visa versa when that shouldn't have been the case. I even got an error related to map definition on a page without any maps or other Leaflet code. I looked at the differences between leaflet demo code and the Rails code and I looked up what turbolinks was supposed to do and got suspicious. Changed $(document).on("turbolinks:load", function() { to $(document).ready(function() { and things started working right. I would have figured this out quicker but I pretty new to all of this. I'll look at @Ben's data: {turbolinks: false} for a less drastic solution, but I'll still give an upvote to the answer. My, I think, final solution is to remove turbolinks altogether. I don't think my site will benefit that much from what turbolinks does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.