I'm trying to accomplish something really easily but I could not solve it to my beginner level in rails. The question is how do you assign a JSON objects attribute to a rails object.. I'm trying to send a request to Google Map's URL with some parameters. Without JSON parsing it works just fine, however when I try to parse it, I receive many errors. The regular JSON response from Google when I query the URL ([http://maps.googleapis.com/maps/api/directions/json?origin=40.983204,29.0216549&destination=40.99160908659266,29.02334690093994&sensor=false][1]) is like down below;
{
"routes" : [
{
"bounds" : {
"southwest" : {
"lat" : 40.98289,
"lng" : 29.02054
},
"northeast" : {
"lat" : 40.99148,
"lng" : 29.02388
}
},
"summary" : "Mühürdar Cd",
"waypoint_order" : [],
"legs" : [
{
"start_location" : {
"lat" : 40.98322,
"lng" : 29.02166
},
"distance" : {
"text" : "1.3 km",
"value" : 1324
},
And goes on.
The code I have to get the "summary" attribute is;
@request = Net::HTTP.get(URI.parse('http://maps.googleapis.com/maps/api/directions/json?origin=40.983204,29.0216549&destination=40.99160908659266,29.02334690093994&sensor=false'))
@result=JSON.parse(@request)["routes"]["summary"]
I wanted to ask what would be the proper way for me to get the summary attribute from the response?
hash['routes'][0]['legs'][0]['duration']and it gets to a point where I receive a JSON request like{ "text" : "6 mins", "value" : 373 }. But I cannot reach neither text or value. What should I add to the end?