2017-03-08 127 views
1

數據錯誤告訴我,該方法「[]」沒有在線路127
這是我的代碼中定義和。我不看到錯誤錯誤紅寶石從數組訪問在軌道上

def verificar_area archivo 
bandera= false 
Spreadsheet.client_encoding = 'UTF-8' 
book = Spreadsheet.open archivo 
@wk = book.worksheet 0 

areas = ["Secundaria", 
"Preparatoria", 
"Universitario", 
"Edad 11 a 15 años", 
"Edad de 16 a 19 años", 
"Solo estudian", 
"Adolescentes que trabajan y estudian"] 

(1 .. @wk.row_count).each do |index_renglon| 
    @renglon_excel = @wk.rows[index_renglon] 
    [email protected]_excel[8]      #This is the line 127 
    if areas.include?(area) 
     bandera=true 
    else 
     bandera=false 
     break 
    end #fin if 
    end #fin for 
    return bandera 
end 

在瀏覽器中的錯誤是這樣 this is the line 127 => area=@renglon_excel[8]

回答

1

你所得到的錯誤,因爲@renglon_excelnil針對特定迭代

@renglon_excel[8] 

而你試圖用[8]索引來訪問nil

爲了避免這種情況,你可以添加一個檢查

@renglon_excel = @wk.rows[index_renglon] 
next unless @renglon_excel 
area = @renglon_excel[8] 
+0

也'p @renglon_excel [8]'如果你曾經好奇那是什麼價值。 – tadman