这是我正在处理的哈希,
a = {
#...
:fares => {
:itinerary_fare => {
:segment_names=>"C",
:free_seats => "6",
:fare_for_one_passenger => {
:free_seats=>"0",
:@currency => "TL",
:@non_refundable => "false",
:@price => "439.0",
:@service_fee => "25.0",
:@tax => "33.0",
:@type => "Y"
},
:@currency => "TL",
:@non_refundable => "false",
:@price => "439.0",
:@service_fee => "25.0",
:@tax => "33.0",
:@type => "C"
},
:@currency => "TL",
:@tax => "33.0"
},
#..
}
Run Code Online (Sandbox Code Playgroud)
还有另一个例子http://pastebin.com/ukTu8GaG.
给我头脑的代码,
a[:fares][:itinerary_fare].each do |f|
puts f[:@price]
end
Run Code Online (Sandbox Code Playgroud)
如果我把它写入控制台,它会给我"无法将符号转换为整数"错误.但如果我写,a[:fares][:itinerary_fare][:@price]它的效果非常好.
如果我将代码写入haml文件,最奇怪的部分是
%tbody
-@flights.each do |a|
%tr.flight
%td
-a[:fares][:itinerary_fare].each do |f|
-puts f[:@price] #Weird stuff happens here
.prices
%input{:type=>"radio",:name=>"selectedfight",:value=>"#{a[:id]}"}
= f[:@price]
%br
Run Code Online (Sandbox Code Playgroud)
它有效,它将价格打印到我的控制台,但它在相同的线路上失败了.
can't convert Symbol into Integer file: flights.haml location: [] line: 18
Run Code Online (Sandbox Code Playgroud)
这是我见过的最令人不安的错误,谢谢你的帮助.
大多数时候有超过1 :itinerary_fare,我必须迭代.