在rails上访问ruby中的数据时出错

该错误告诉我方法“[]”没有在第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] area=@renglon_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]

你得到的错误,因为@renglon_excel nil特定的迭代

 @renglon_excel[8] 

而你正尝试访问与索引[8] nil

为了避免这个,你可以添加一个支票

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