Google map to_html not working

Hi,there

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

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
it!
The error occured while evaluating nil.zoom=) on line #1 of
app/views/admin/content/_place_map.rhtml:
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!

Jacquie,

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 = Map.new(:name => ‘placemapper’, :width=>800, :height => 600,
:controls => [:zoom, :type], :draggable => true)
# default type
@map.type = :map
# default zoom level
@map.zoom = 13

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

params[:query].downcase])
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 << Cartographer::Marker.new( :name => 

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

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 = Map.new(:name => 'placemapper', :width=>800, :height => 600,
  longitude = place.longitude
      @map.markers << Cartographer::Marker.new( :name =>

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

@map = Map.new(:name => 'placemapper', :width=>800, :height => 600,
  longitude = place.longitude
      @map.markers << Cartographer::Marker.new( :name =>

=>“get_more_info.rjs”
<% @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
new
page and start a brand new request, which no longer has all of the code
you
ran before the redirect in memory. You need to a do a render instead of
a
redirect.


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.

@map.center = places.keys.last
breakpoint
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?

Thanks!