TheChamp帮助我解决了一系列哈希问题。谢谢。现在我想改进一下。它在观点中非常混乱
这是我的代码库。 (供我们考虑,API响应的一部分 - http://jsfiddle.net/PP9N5/)
模型
class Cleartrip
include HTTParty
debug_output $stdout
base_uri "api.staging.cleartrip.com/air/1.0/search"
headers 'X-CT-API-KEY' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
format :xml
def self.get_flight
response = get("?from=DEL&to=BLR&depart-date=2014-08-10&adults=1&children=0&infants=0")
if response.success?
response
else
raise response.message
end
end
控制器
# This does nothing
expires_in 20.minutes, public: true
@flight = Cleartrip.get_flight
浏览
<table>
<tbody>
<% @flight["air_search_result"]["onward_solutions"]["solution"].each do |h| %>
<tr>
<td> # This gets the flight info
<% Array.wrap(h["flights"]["flight"]["segments"]["segment"]).each do |segment| %>
<strong><%= segment['airline'] %></strong> <br>
<%= segment['departure_airport'] %> - <%= segment['departure_date_time'] %> ||
<%= segment['arrival_airport'] %> - <%= segment['arrival_date_time'] %> <br>
<% end %>
<hr>
</td>
<td> # this gets the type of fare, Refundable/ Non-refundable
<%= h["pax_pricing_info_list"]["pax_pricing_info"]["pricing_info_list"]["pricing_info"]["fare_type"] %>
</td>
<td> # This gets the fare structure
<% h["pax_pricing_info_list"]["pax_pricing_info"]["pricing_info_list"]["pricing_info"]["pricing_elements"]["pricing_element"].each do |f| %>
<%= f['category']%> - <%= f['amount'] %> <br>
<% end %>
</td>
<td> # The pricing summary
<strong><%=h["pricing_summary"]["total_fare"] %></strong>
</td>
</tr>
<% end %>
</tbody>
</table>
赞赏一般准则。
感谢。