Google map to_html not working


This question might sound a bit out-dated but I am still struggling with

When I try to display the google map in my application, I rendered
@map.to_html like everyone else does, but didnt get any result. The
error shows as follows

ActionView::TemplateError (You have a nil object when you didn’t expect
The error occured while evaluating nil.zoom=) on line #1 of
1: <% @map.zoom = 4 %>
2: <%= @map.to_html %>

By using the google map API,I followed the instruction in readme
strictly. register for a new key and include the cartographer module in
RAILS_ROOT/config/environment.rb by require ‘cartographer’

It looks like I was able to get @map.to_html in my controller but not
able to render in the view.

Anyone encountered this problem before?

Thanks for any help!


It looks like your view can’t see the @map instance, any chance you are
actually trying to make this call in a partial or that the object
wasn’t created correctly in the contoller? Can you paste a code snippet
for us to look at?

Thanks for your reply,glenn.

Yeah,thats what I thought,but not sure why.

I have @map in my map_controller.rb as is shown below

def index
# create the map
@map = => ‘placemapper’, :width=>800, :height => 600,
:controls => [:zoom, :type], :draggable => true)
# default type
@map.type = :map
# default zoom level
@map.zoom = 13

places =
place = Place.find(:first, :conditions => [%{location = ? }, 

if !place.nil?
longitude = place.longitude
latitude = place.latitude
longlat = [longitude, latitude]

  places[longlat] = [place.address << "," << place.suburb << "," << 

place.state << “,” << “Australia”]

  i = 0
  places.each { |key,value|
      text = ""
      value.each { |v| text << v }
      @map.markers << :name => 

“marker_#{i}”, :position => key, :info_window => text )
i += 1
# center the map = places.keys.last and @places.keys.last
both are arrays
redirect_to :controller=>‘admin/content’, :action
redirect_to :controller => ‘admin/content’, :action

Then in views/admin/content/display_map.rjs

page.insert_html :bottom, ‘my_map’, :partial => ‘place_map’
page.visual_effect :appear, ‘my_map’

Then in views/admin/content/place_map.rhtml

<% @map.zoom = 4 %>
<%= @map.to_html %>

would it be because I used rjs? but the second redirect_to works fine.

anybody has some ideas?

Thanks a lot!

Thanks, Scott. I solved this problem by rendering an action under the
same controller.

Thank you all!

Scott B. wrote:

On 11/23/06, jacquie [email protected] wrote:

@map = => 'placemapper', :width=>800, :height => 600,
  longitude = place.longitude
      @map.markers << :name =>

On 11/23/06, jacquie [email protected] wrote:

@map = => 'placemapper', :width=>800, :height => 600,
  longitude = place.longitude
      @map.markers << :name =>

<% @map.zoom = 4 %>
<%= @map.to_html %>

would it be because I used rjs? but the second redirect_to works fine.

anybody has some ideas?

It’s because you are doing a redirect. That is causing to to jump to a
page and start a brand new request, which no longer has all of the code
ran before the redirect in memory. You need to a do a render instead of

Scott B.
Electro Interactive, Inc.
Office: 813-333-5508

Unfortunately I need to keep on this topic since the map is not
displaying at all.

in my controller, i set up a breakpoint before rendering the rjs
template. = places.keys.last
render :action =>‘index.rjs’

I print out the @map.to_html at this breakpoint and it gives out

It looks fine.

However,in my webpage,I’ve only had

The webpage where it should display the map is completely blank.

anyone has the same/similar problem before?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs