Mel Mel - 6 months ago 76
Javascript Question

Rails 4 - Google Maps with gmaps4rails gem

I am trying to figure out how to use gmaps4rails gem in my Rails 4 app.

I have a view partial in which I have inserted the 3 script tags shown in the documentation, replacing the API key with my own (which is stored in my environment secrets file).

<script src="//['GOOGLE_MAPS_API_KEY']"></script>

I think I may have done this incorrectly, because I can't currently load maps. The error message I see when I inspect the console from Chrome is:

util.js:220 Google Maps API warning: InvalidKey

Can anyone see if I have made an error in the way I have inserted my API key to this script?

Vic Vic

You are inserting a ruby snippet into a .html.erb file, so u need the <%=%> to interpolate the ruby string

<script src="//<%= ENV['GOOGLE_MAPS_API_KEY'] %>"></script>

Check inspect element of ur html page to see that the url is interpolated correctly.