这是我正在处理的哈希,
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"
},
#..
}
这里还有另一个例子http://pastebin.com/ukTu8GaG。
让我头疼的代码,
a[:fares][:itinerary_fare].each do |f|
puts f[:@price]
end
如果我将它写入控制台,它会给我“无法将符号转换为整数”错误。但如果我写,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
它可以工作,将价格打印到我的控制台,但在同一行却失败了。
can't convert Symbol into Integer file: flights.haml location: [] line: 18
这是我见过的最令人不安的错误,感谢您的帮助。
大多数时候有超过 1 :itinerary_fare
,我必须迭代。