저의 가난한 영어에 대해 죄송합니다. 아래와 같은 오류가 발생했습니다.
undefined method `[]=' for nil:NilClass
app/controllers/tasks_controller.rb:69:in `block in show'
app/controllers/tasks_controller.rb:67:in `each'
app/controllers/tasks_controller.rb:67:in `each_with_index'
app/controllers/tasks_controller.rb:67:in `show'
다음은 'tasks_controller.rb'의 코드입니다.
@teammates_form = Array.new(@teammates.size-1){Hash.new}
@teammates.each_with_index do |t, idx|
if t.id != current_user.id
@teammates_form[idx]['id'] = t.id # <--- line 69
@teammates_form[idx]['name'] = t.name
@teammates_form[idx]['t_id'] = @task.id
end
end
하지만 다음과 같은 코드를 변경하면
@teammates_form[0]['id'] = t.id
@teammates_form[0]['name'] = t.name
@teammates_form[0]['t_id'] = @task.id
작동합니다 ... 배열에서 인덱스를 사용할 수없는 이유를 모르겠습니다.
도움을 주셔서 미리 감사드립니다.
# ⇓⇓ ? WHY?
@teammates_form = Array.new(@teammates.size-1){Hash.new}
요소가 1 개 더 짧기 @teammates
때문에 의 마지막 반복에서이 오류가 발생합니다 @teammates_form
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다