아래 코드에서이 오류가 발생하는 이유는 누구나 알 수 있습니까?오류 : 문자열을 정수로 변환하지 않음
def total_single_order(one_order)
single_order_totals = Hash.new(0)
one_order.each do |coffee_sku, coffee_info_hash|
binding.pry
single_order_totals[coffee_sku]['cost_to_customer'] = (coffee_info_hash["RetailPrice"].to_f * coffee_info_hash['num_bags]'].to_f)
single_order_totals[coffee_sku]['cost_to_company'] = (coffee_info_hash["PurchasingPrice"].to_f * coffee_info_hash['num_bags]'].to_f)
end
single_order_totals
end
total_single_order(one_order)
당신은 정확하게 코드를 쓰다나요? 이 코드는'single_order_totals [coffee_sku] [ 'cost_to_customer']'에 할당 된 줄에''undefined method [] for nil' 오류를 생성해야합니까? 스택 추적 상단에 줄을 식별하는 정확한 오류를 표시하십시오. –
감사합니다. 이것이 오작동을 일으키기 위해 오타 오류 수정을 한 후에 나는 이렇게 초기화해야했습니다 : single_order_totals = Hash.new {| hash, key | hash [key] = []} – John