YM4R_GM plugin... This controller code works but clearly has limitations... map_1 = GMarker.new([@salons[0].lat, @salons[0].lng]) @map.overlay_init(map_1) but I really need this in a loop... for salon in @salons do map_id += 1 map_id_ = "map_id_" + map_id.to_s map_id = Gmarker.new([salon.lat, salon.lng]) @map.overlay_init(map_id) end But inside the loop, I get the following error that I can''t seem to figure out a way to prevent... NameError (uninitialized constant SalonsController::Gmarker): How to use the Gmarker method inside a loop? Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 5, 11:19 am, Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote:> YM4R_GM plugin... > > This controller code works but clearly has limitations... > > map_1 = GMarker.new([@salons[0].lat, @salons[0].lng]) > -mDGcsIj0EBRcKHiaeZqq9g@public.gmane.org_init(map_1) > > but I really need this in a loop... > > for salon in @salons do > map_id += 1 > map_id_ = "map_id_" + map_id.to_s > map_id = Gmarker.new([salon.lat, salon.lng]) > @map.overlay_init(map_id) > end > > But inside the loop, I get the following error that I can''t seem to > figure out a way to prevent... > > NameError (uninitialized constant SalonsController::Gmarker): > > How to use the Gmarker method inside a loop? > > Craig > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean.Ruby is case-sensitive. And that loop is rather sketchy... what you''re doing can just be replaced with something like @salons.each {|salon| @map.overlay_init GMarker.new([salon.lat, salon.lng])} If you end up actually needing the array indices, each_with_index will do nicely. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, 2010-02-05 at 10:17 -0800, pharrington wrote:> On Feb 5, 11:19 am, Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote: > > YM4R_GM plugin... > > > > This controller code works but clearly has limitations... > > > > map_1 = GMarker.new([@salons[0].lat, @salons[0].lng]) > > @map.overlay_init(map_1) > > > > but I really need this in a loop... > > > > for salon in @salons do > > map_id += 1 > > map_id_ = "map_id_" + map_id.to_s > > map_id = Gmarker.new([salon.lat, salon.lng]) > > @map.overlay_init(map_id) > > end > > > > But inside the loop, I get the following error that I can''t seem to > > figure out a way to prevent... > > > > NameError (uninitialized constant SalonsController::Gmarker): > > > > How to use the Gmarker method inside a loop? > >> Ruby is case-sensitive. And that loop is rather sketchy... what you''re > doing can just be replaced with something like > > @salons.each {|salon| @map.overlay_init GMarker.new([salon.lat, > salon.lng])} > > If you end up actually needing the array indices, each_with_index will > do nicely.---- friggin awesome - thanks loop was sketchy because I myself was getting loopy after trying so many variations... Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I don''t think you''re going to like this. I think the issue is that in the for loop you need to capitalize the m in Gmarker (as in your original code). Also, ruby offers something called each with index. Your code could become something like @salons.each_with_index |salon, map_id| map_id_ = "map_id_" + map_id.to_s map_id = GMarker.new([salon.lat, salon.lng]) @map.overlay_init(map_id) end Hope that helps. Luke On Feb 5, 8:19 am, Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote:> YM4R_GM plugin... > > This controller code works but clearly has limitations... > > map_1 = GMarker.new([@salons[0].lat, @salons[0].lng]) > -mDGcsIj0EBRcKHiaeZqq9g@public.gmane.org_init(map_1) > > but I really need this in a loop... > > for salon in @salons do > map_id += 1 > map_id_ = "map_id_" + map_id.to_s > map_id = Gmarker.new([salon.lat, salon.lng]) > @map.overlay_init(map_id) > end > > But inside the loop, I get the following error that I can''t seem to > figure out a way to prevent... > > NameError (uninitialized constant SalonsController::Gmarker): > > How to use the Gmarker method inside a loop? > > Craig > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sat, 2010-02-06 at 07:16 -0800, Luke Cowell wrote:> I don''t think you''re going to like this. I think the issue is that in > the for loop you need to capitalize the m in Gmarker (as in your > original code). > > Also, ruby offers something called each with index. Your code could > become something like > > @salons.each_with_index |salon, map_id| > map_id_ = "map_id_" + map_id.to_s > map_id = GMarker.new([salon.lat, salon.lng]) > @map.overlay_init(map_id) > end > > Hope that helps.---- duh - I missed the Gmarker/GMarker issue. That clearly was the problem but pharrington gave me some very concise/clever way of handling it which worked beautifully. Thanks Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.