I'm using google-maps-for-rails (gmap4rails). The gem has a method that created an array to use in javascript.
hash = Gmaps4rails.build_markers(@users) do |user, marker|
marker.lat user.latitude
marker.lng user.longitude
end
This results in the following:
[{:lat=>33.462209, :lng=>-86.812519, :infowindow=>"hello"}]
or simpler to read
[
{
:lat => 33.462209,
:lng => -86.812519,
:infowindow => "hello"
}
]
I am trying to use this in coffeescript, but where I pass this array into the coffeescript from a variable in my controller. (I am using Paloma JS for page-specific js, where you can access controller variables in your coffeescript.)
I've tried to convert the array into JSON and used gsub to replace characters, but I've been having difficulty.
In specific, I tried to convert to JSON then remove the commas, hash.to_json.gsub(/,/, ''), which outputs
[{"lat":33.462209"lng":-86.812519"infowindow":"hello"}]
I think I need to remove the brackets, { and } here, and possibly include the proper line indentions for coffeescript.
In the end, it should look like this:
[
lat: 33.462209
lng: -86.812519
infowindow: "hello"
]
Any ideas?? Thanks for the time.