Controller code and uninitialized constants

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.

On Feb 5, 11:19 am, Craig W. [email protected] wrote:

  map_id += 1

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.

On Fri, 2010-02-05 at 10:17 -0800, pharrington wrote:

for salon in @salons do

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.

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 Sat, 2010-02-06 at 07:16 -0800, Luke C. wrote:

  @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.

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