YM4R ActionView::TemplateError and Related Errata

Ruby on Rails Add comments

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.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

4 Responses to “YM4R ActionView::TemplateError and Related Errata”

  1. Mattia Says:

    Thank you! It has been a life saver! Greetings from Italy

  2. vibha Says:

    Thank you so much for this. I think this line should be added in the README of the plugin.

  3. Zaid A. Says:

    thanks, that solved my issue.

  4. Jeff Says:

    Wow. Thanks a ton. Saved me a bunch of time trying to figure this out. Perfect post.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in