1

The error tells me that the method '[]' is not defined in the line 127
this is my code and Idon't see the error

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

the error in the browser is this this is the line 127 => area=@renglon_excel[8]

1 Answer 1

1

You are getting the error because @renglon_excel is nil for that specific iteration

@renglon_excel[8]

And you are trying to access with index of [8] on nil

To avoid this you can add a check

@renglon_excel = @wk.rows[index_renglon]
next unless @renglon_excel
area = @renglon_excel[8]
Sign up to request clarification or add additional context in comments.

1 Comment

Also p @renglon_excel[8] if you're ever curious what that value is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.