GMaps4Rails and Turbolinks not loading without full page refresh

前端 未结 6 1718
悲哀的现实
悲哀的现实 2020-12-28 09:32

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 hav

6条回答
  •  攒了一身酷
    2020-12-28 10:01

    As can be found in this Github issue, you can include google scripts to all your pages. That fixes the issue with Turbolinks not executing gmaps4rails javascripts for newly navigated pages.

    Note that gmaps4rails gem has javascript dependencies, namely:

    
    
    

    You can add them to all your pages typically by editing app/views/layouts/application.html.erb.

    application.html.erb

    ....
    
    ...
      <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
      <%= csrf_meta_tags %>
    
      # insert the following two lines
      
      
    
    
    ...
    

    Also, don't forget to add the source code to your asset pipeline by editing app/assets/javascripts/application.js

    application.js

    Add this:

    //= require gmaps/google
    

    Now, the map should be loading without you having to refresh the page.

提交回复
热议问题