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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/23/06, jacquie <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > 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? >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 Becker Electro Interactive, Inc. Office: 813-333-5508 http://www.ElectroInteractive.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, Scott. I solved this problem by rendering an action under the same controller. Thank you all! Scott Becker wrote:> On 11/23/06, jacquie <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> @map = Map.new(:name => ''placemapper'', :width=>800, :height => 600, >> longitude = place.longitude >> @map.markers << Cartographer::Marker.new( :name => >-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 <div id=''placemapper'' style=''width:800px; height:600px'' class=''gmap''></div> <script type=\"text/javascript\"> /*<![CDATA[ */ var placemapper; var marker_0; function marker_0_infowindow_function(){marker_0.openInfoWindowHtml(\"17 Edward ave,kingsford,NSW,Australia\");} function initialize_gmap_placemapper() { if (GBrowserIsCompatible()) { placemapper = new GMap(document.getElementById(\"placemapper\")); placemapper.centerAndZoom(new GPoint(151.222, -33.9213), 13); placemapper.setMapType(G_MAP_TYPE); placemapper.addControl(new GSmallZoomControl()); placemapper.addControl(new GMapTypeControl()); marker_0 = new GMarker(new GPoint(151.222, -33.9213)); GEvent.addListener(marker_0, \"click\", function() {marker_0.<strong>openInfoWindowHtml</strong>(\"17 Edward ave,kingsford,NSW,Australia\");}); placemapper.addOverlay(marker_0); } } if (typeof window.onload != ''function'') window.onload = initialize_gmap_placemapper; else { old_before_cartographer_placemapper = window.onload; window.onload = function() { old_before_cartographer_placemapper(); initialize_gmap_placemapper() } } //]]> </script> It looks fine. However,in my webpage,I''ve only had <div id="my_map" style="opacity: 0.999999;"> <div id="placemapper"> <div class="gmap" style="width: 800px; height: 600px;" id="placemapper"/> </div> </div> The webpage where it should display the map is completely blank. anyone has the same/similar problem before? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---