nil的未定义方法'id':NilClass围绕行提取源 42
这是我的take_assement.controller.rb
文件中显示错误的部分。
我开始的那条线是第36行。因此,第42行有一个问题。
def start
if current_user.taken_any_assessment?.all?
redirect_to user_root_path
else
Portal.all.sort_by(&:display_order).each do |portal|
if !current_user.taken_assessment
(portal.current_assessment(current_user))
@assessment = Assessment.find(portal.current_assessment(current_user).id)
if !@assessment.has_student_taken_this_assessment?(current_user)
AssessmentResult.create!(student: current_user, assessment: @assessment, last_question: 0)
@question = @assessment.questions.first
else
last_position = AssessmentResult.where(student: current_user, assessment: @assessment).first
@question = @assessment.questions.where(position: last_position.last_question+1).first
end