Search code examples
ruby-on-rails-3gmaps4rails

ReplaceMarkers with gmaps4rails using javascript


I'm following this example here

Dynamically load Google Maps Markers with gmaps4rails

I'm trying to use a .js request instead of .json so I can render some other info within the same controller request. Using the .json method works great but once I switch to .js, it doesn't work. The data being sent is still run through the .to_gmaps4rails method to convert it into the JSON data.

When responding to the .json request, the console.log shows the response data interpreted as marker objects but it's just string data when responding to the .js request.

Any help would be much appreciated!


Solution

  • You should simply use:

    JSON.parse(string)
    

    Since result from .js isn't automatically converted to an object.