diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 593d6bf53..018a293e3 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -631,7 +631,7 @@ class StudentWorkController < ApplicationController unless @homework.save logger.debug @homework.errors.full_messages else - student_work = @homework.student_works.where(user_id: User.current.id).first + student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first end end student_work diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9b2d49f2d..d71b24fc8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -354,7 +354,7 @@ class UsersController < ApplicationController @user = User.current @homework = HomeworkCommon.find(params[:homework_id]) @is_test = params[:is_test] == 'true' - @student_work = @homework.student_works.where(user_id: User.current.id).first + @student_work = StudentWork.where(homework_common_id: @homework.id, user_id: User.current.id).first if @student_work.nil? @student_work = StudentWork.new end @@ -369,7 +369,7 @@ class UsersController < ApplicationController def user_commit_homework homework = HomeworkCommon.find(params[:homework]) - student_work = homework.student_works.where(user_id: User.current.id).first + student_work = StudentWork.where(homework_common_id: homework.id, user_id: User.current.id).first if student_work student_work.save flash[:notice] = l(:notice_successful_create)