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

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.

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

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

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.