Google Maps Integration with JSON - CircularReferenceError

Update II

I get it. When using google maps api, the model should not be called "maps". to_json works after I created a new model name.

Update

@maps is the name of my model, it contains information such as address, longitude, latitude. When I replace <%= @maps.to_json %>; to <%= @maps %> <%= @maps.to_json %>; to <%= @maps %> , HTML displays ActiveRecord :: Relation: 0x1044e8ba8 & gt

In the console:

 >> b= Map.last => #<Map id: 6, first_name: "James", last_name: "", address: "2478 Goldenrod Ln, Perrysburg, OH", address2: "", zip: "", city: "", phone: "", campaign_id: nil, email: "", employer: "", occupation: "", created_at: "2010-04-02 20:58:15", updated_at: "2010-04-02 20:58:15", latitude: 41.556996, longitude: -83.627157> >> b.to_json => "{\"occupation\":\"\",\"city\":\"\",\"address\":\"2478 Goldenrod Ln, Perrysburg, OH\",\"zip\":\"\",\"latitude\":41.556996,\"created_at\":\"2010-04-02T20:58:15Z\",\"address2\":\"\",\"updated_at\":\"2010-04-02T20:58:15Z\",\"campaign_id\":null,\"id\":6,\"phone\":\"\",\"last_name\":\"\",\"employer\":\"\",\"longitude\":-83.627157,\"first_name\":\"James\",\"email\":\"\"}" 

Rails Server:

I am working on Rails 3.0.0.beta2, following the Advanced Rails Recipes β€œRecipe # 32, Mark Locations on a Google Map” and I hit the road block.

The following code returns the object "ActiveSupport :: JSON :: Encoding :: CircularReferenceError" "the object itself" on line 3. This code represents the file /layouts/maps.html.erb

 <% if @maps -%> <script type="text/javascript"> var maps = <%= @maps.to_json %>; </script> <% end -%> 

This is my first attempt at rendering JSON, and I don't know how to debug this problem. Do you have any experience with this? What can cause this problem?

Thank you in advance!

+4
source share
2 answers

I get it! when using google maps api my model should not be called "maps". to_json works after I created a new model name.

0
source

I also see this error and find it very difficult to debug, because calling as_json on an object returns no errors, and to_json - !?

Try extracting date and time attributes from your model and see if that helps. I was looking for this problem and some earlier solutions (since 2007) recommend correcting the JSON date encoding.

0
source

Source: https://habr.com/ru/post/1305914/


All Articles