Using Guilhem Vellut’s brilliant YM4R plugin for Google map and other mapping mashups you might run into the following issue:
ActionView::TemplateError (yourdomain.com) on line #3 of app/views/google_map
s/show.html.erb:
1: <% content_for :head do %>
2:
3: <%= GMap.header(:with_vml => false) %>
4: <%= @map.to_html %>
5: <style type=”text/css”>
6: #map_div {height:500px;}/var/www/apps/yourapp/releases/20090210175842/vendor/plugins/ym4r_gm/l
ib/gm_plugin/key.rb:28:in `get’
Another related error might be a Ym4r::GmPlugin::AmbiguousGMapsAPIKeyException, which is actually the underlying error of the above issue, called in the quoted line 28 of ym4r_gm/lib/gm_plugin/key.rb.
The cause of the problem is that you call
<%= GMap.header(:with_vml => false) %>
in your view instead of
<%= GMap.header(:with_vml => false, :host => request.host) %>
Yep, it’s that simple. As soon as you have multiple hosts configured in your gmaps_api_key.yml file, you need to specify the host option. Guilhelm’s comment in the code (line 23 & 24 of key.rb):
#For this environment, multiple hosts are possible.
#:host must have been passed as option
To be honest, the host could have been defaulted to the current request’s host in the plugin, but as things stand :host => <some_host> has to be passed.
Now you can also do sth. like this in your :gmaps_api_key.yml file, for example if you have several apps running on phusion passenger in development as discussed in this railscast:
development:
localhost: <api key>
yourdomain.local: <api key>test: <api key>
production:
yourdomain1.com: <api key>
yourdomain2.com: <api key>
Hope it helps.
February 3rd, 2010 at 10:03 pm
Thank you! It has been a life saver! Greetings from Italy
April 7th, 2010 at 12:04 pm
Thank you so much for this. I think this line should be added in the README of the plugin.
April 21st, 2010 at 3:03 pm
thanks, that solved my issue.
June 11th, 2010 at 4:57 pm
Wow. Thanks a ton. Saved me a bunch of time trying to figure this out. Perfect post.