gmaps4rails: Uncaught ReferenceError: Gmaps is not defined

喜你入骨 提交于 2019-12-13 13:59:02

问题


I want to inclued maps into my rails application (I am using Rails 3.2.11 with asset pipeline) via the Gmaps4Rails gem. Following the setup instructions for this gem on https://github.com/apneadiving/ , I have

  • included the gem in the Gemfile via gem gmaps4rails
  • copied the assets to my rails app using the generator provided by the gem rails generate gmaps4rails:install. After doing that, there is the gmaps4rails.css in the app\assets\stylesheetsfolder and 5 coffeescripts in the àpp\assets\javascripts\gmaps4rails` folder
  • included the Javascripts via <%= yield :scripts %>. Side-question: Is it sufficient to put this btw. the closing body and the closing html tag, or should there be a footer tag used where the Javascripts are yielded?

      ...
      </body>
      <%= yield :scripts %>
    </html>
    

Model, migrations, etc. are all set up and should work. Finally, in the view, I am calling <%= gmaps4rails(@json) %>.

Unfortunately, I get a JavaScript error Uncaught ReferenceError: Gmaps is not defined. The following screenshot shows how Chrome reports the error in the gmaps4rails Javascripts:

The result is that the map is not rendered with any concent; there's just the CSS wrapper for the map but without any content.

I am not able to fix this, so I need your support.

What I tried out and noticed so far:

  • The two Javascripts from Google before the script where the error occurs seem to load dynamically and after the last Javascript is loaded. I have downloaded the JavaScripts directly from the source, built local files out of them, and included the into the assets pipeline, however, this did not resolve the issue.
  • I assume that Gmaps (which cannot be referenced) has been renamed in the previous loaded library Javascripts. However, as I don't know how this works in detail, I cannot follow up here and check it.

回答1:


I figured out that I missed to add the gmaps4rails Javascripts properly to the asset pipeline.

Adding either

    //= require_tree .

or

    //= require gmaps4rails/gmaps4rails.bing
    //= require gmaps4rails/gmaps4rails.googlemaps
    //= require gmaps4rails/gmaps4rails.mapquest
    //= require gmaps4rails/gmaps4rails.openlayers
    //= require gmaps4rails/gmaps4rails.base

to application.js would fix the issue.

However, as it seems that I have forgotten to add

    //= require_tree .

completely, I have added it just as the last of the includes to my application.js.



来源:https://stackoverflow.com/questions/16766366/gmaps4rails-uncaught-referenceerror-gmaps-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!