GMaps4Rails and Turbolinks not loading without full page refresh

Shaun picture Shaun · Dec 10, 2012 · Viewed 7.7k times · Source

I'm using gmaps4rails to load a map on a "clients" show page. I've integrated turbolinks to make the app speadier all together, but now I'm hitting an issue where I have to refresh the page with the map for the map to show up. All I get is a blank map frame. When I refresh the page, the map shows up correctly.

I tried adding the gem 'jquery-turbolinks', but the problem persists.

In view:

<%= gmaps("map_options" => {:container_class => "map_container_renamed", "zoom" => 15, "auto_zoom" => false},"markers" => { "data" => @json }) %>

In application.js

//= require jquery
//= require turbolinks
//= require jquery.turbolinks
//= require jquery_ujs
//= require twitter/bootstrap
//= require_tree .

Gist of page source where map is blank here.

Answer

Shaun picture Shaun · Dec 11, 2012

The fix ended up that I need a full page load for the scripts to refresh.

Adding

'data-no-turbolink' => true

to the link that goes to the maps page worked.

For example, if I have an index page of clients, and I have a map of where the client lives on the show page, the link to go to the show page would be formatted as below:

<%= link_to 'View Client', client, class: "btn", 'data-no-turbolink' => true %>

This will cause a full refresh of the html and javascript, instead of just the changed html.