no implicit conversion from nil to integer - when trying to add anything to array

前端 未结 4 793
天涯浪人
天涯浪人 2021-01-04 03:14

I\'m trying to build a fairly complex hash and I am strangely getting the error

no implicit conversion from nil to integer

when I use the l

4条回答
  •  我在风中等你
    2021-01-04 03:52

    This seems to have been completely unrelated to anything that had anything to do with manufacturer_cols after all.

    I had arrived at the manufacturer_cols bit because if I commented that out, it ran fine.

    However, if I commented out the part where I ran through the csv further down the page, it ran fine also.

    It turns out the error was related to retrieving attempting to append the base_field when it was nil.

    I thought I could use

    manufacturer_cols.each do |col|
       base_value = row[col[:row_index].to_i]
    
       if col[:merges]
           col[:merges].each do |merge|
               base_value += merge[:separator].to_s + row[merge[:merge_row_index]]
           end
       end
    end
    

    unfortunately, that caused the error. the solution was

     base_value = base_value + merge[:separator].to_s + row[merge[:merge_row_index]]
    

    I hope this helps somebody, 'cause as DigitalRoss alluded to, it was quite a wild goose chase nailing down where in the code this was being caused and why.

提交回复
热议问题