I have this hash that I received from an API, using Httparty. The response was an XML but httparty showed it as a hash. But it is soo deep, it gets confusing to get the values.
{"air_search_result"=>{"xmlns"=>"http://www.cleartrip.com/air/", "onward_solutions"=>{"solution"=>[{"index"=>"1", "pricing_summary"=>{"base_fare"=>"3350.0", "taxes"=>"7828.55", "total_fare"=>"11178.55"}, "flights"=>{"flight"=>{"segments"=>{"segment"=>[{"index"=>"1", "departure_airport"=>"BOM", "arrival_airport"=>"BLR", "departure_date_time"=>"2014-07-06T09:15:00", "arrival_date_time"=>"2014-07-06T10:50:00", "flight_number"=>"639", "airline"=>"AI", "operating_airline"=>"AI", "stops"=>"0", "equipment"=>"319", "duration"=>"5700"}, {"index"=>"2", "departure_airport"=>"BLR", "arrival_airport"=>"DEL", "arrival_terminal"=>"3", "departure_date_time"=>"2014-07-06T20:10:00", "arrival_date_time"=>"2014-07-06T22:40:00", "flight_number"=>"404", "airline"=>"AI", "operating_airline"=>"AI", "stops"=>"0", "equipment"=>"320", "duration"=>"9000"}]}}}, "pax_pricing_info_list"=>{"pax_pricing_info"=>{"pax_type"=>"ADT", "pricing_info_list"=>{"pricing_info"=>{"index"=>"1", "fare_basis_code"=>"SAP30,SAP30", ........
I need to get inside and show airline, departure_airport, etc.
"flights"=>{"flight"=>{"segments"=>{"segment"=>
<% @flight["air_search_result"]["onward_solutions"]["solution"].each do|h| %>
<strong><%=h["pricing_summary"]["total_fare"] %></strong> -
<% h["flights"]["flight"]["segments"]["segment"] %>
<%= end %>
When I include ["airline"], rails 4 conviniently says can't convert String into Integer. But I can get ["pricing_summary"]["total_fare"]
I tried many variations, nested loops but alas, it does not work.
I am also wondering if there is any gem or method which can directly give the result instead of such deep traversing
EDIT
<% @flight["air_search_result"]["onward_solutions"]["solution"].map do|h| %>
<strong><%=h["pricing_summary"]["total_fare"] %></strong> -
<% h["flights"]["flight"]["segments"]["segment"].map do |s| %>
<%= s["airline"] %>
<% end %><br> <hr>
<% end %>