@ -44,7 +44,7 @@ class ExerciseQuestionsController < ApplicationController
end
end
if @exercise_question . save
if @exercise_question . save !
#为选择题(包括单选和多选)的时候,创建问题选项
ques_type = @exercise_question . question_type
if ques_type < = Exercise :: MULTIPLE
@ -59,7 +59,7 @@ class ExerciseQuestionsController < ApplicationController
:choice_text = > choice . strip
}
question_choices = @exercise_question . exercise_choices . new ( choice_option )
question_choices . save
question_choices . save !
end
#标准答案的存储,如:["1","2","3"..]等, 1对应A, 2对应B, 3对应C。。。
standard_answer . each do | a |
@ -69,7 +69,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_choice_id = > choice_id #即为选择的位置参数
}
question_standard_answer = ExerciseStandardAnswer . new ( standard_option )
question_standard_answer . save
question_standard_answer . save !
if standard_answer . count > 1 && ques_type == Exercise :: SINGLE #当标准答案数大于1, 且不为多选时, 修改为多选
@exercise_question . update_attribute ( " question_type " , Exercise :: MULTIPLE )
elsif standard_answer . count == 1 && ques_type == Exercise :: MULTIPLE
@ -85,8 +85,8 @@ class ExerciseQuestionsController < ApplicationController
:choice_position = > c ,
:choice_text = > choice . strip
}
question_choices = @exercise_question . exercise_choices . create ( choice_option )
question_choices . save
question_choices = @exercise_question . exercise_choices . create ! ( choice_option )
question_choices . save !
end
standard_answer = params [ :standard_answers ] #对应选项的id
standard_option = {
@ -94,7 +94,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_choice_id = > standard_answer . first . to_i
}
question_standard_answer = ExerciseStandardAnswer . new ( standard_option )
question_standard_answer . save
question_standard_answer . save !
elsif ques_type == Exercise :: COMPLETION #填空题,每空的参考答案有多个,那么以位置对应
standard_answer = params [ :standard_answers ]
standard_answer . each do | a |
@ -107,7 +107,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text = > n
}
question_standard_answer = ExerciseStandardAnswer . new ( standard_option )
question_standard_answer . save
question_standard_answer . save !
end
end
elsif ques_type == Exercise :: SUBJECTIVE #简答题
@ -119,7 +119,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text = > a ,
}
question_standard_answer = ExerciseStandardAnswer . new ( standard_option )
question_standard_answer . save
question_standard_answer . save !
end
end
elsif ques_type == Exercise :: PRACTICAL #实训题
@ -135,10 +135,10 @@ class ExerciseQuestionsController < ApplicationController
:position = > ( index + 1 ) ,
:question_score = > shixun_scores [ index ] . present? ? shixun_scores [ index ] . to_f . round ( 1 ) : 5
}
ex_shixun_challenge = ExerciseShixunChallenge . create ( shixun_option )
ex_shixun_challenge = ExerciseShixunChallenge . create ! ( shixun_option )
question_score += ex_shixun_challenge . question_score # 问题的分数,为各个关卡分数的总和
end
@exercise_question . update _attributes ( :question_score = > question_score , :shixun_name = > shixun_name )
@exercise_question . update ! ( :question_score = > question_score , :shixun_name = > shixun_name )
end
end
rescue Exception = > e
@ -188,7 +188,7 @@ class ExerciseQuestionsController < ApplicationController
choices_array = params [ :question_choices ]
stan_answer_params = params [ :standard_answers ]
standard_answer = stan_answer_params . present? ? stan_answer_params . uniq . reject ( & :blank? ) : [ ]
@exercise_question . update _attributes ( question_options )
@exercise_question . update ! ( question_options )
#当选项存在时,可修改选项内容,但是不能更改选项的位置(即不能增删选项)
if choices_array . present?
ex_choices = @exercise_question . exercise_choices
@ -218,7 +218,7 @@ class ExerciseQuestionsController < ApplicationController
:choice_text = > choices_array [ i - 1 ] . strip
}
question_choices = @exercise_question . exercise_choices . new ( choice_option )
question_choices . save
question_choices . save !
end
end
end
@ -243,7 +243,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_choice_id = > s . to_i #即为选择的位置参数
}
question_standard_answer = ExerciseStandardAnswer . new ( standard_option )
question_standard_answer . save
question_standard_answer . save !
end
end
@ -296,7 +296,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text = > null_choice_text [ i - 1 ]
}
question_standard_answer = ExerciseStandardAnswer . new ( standard_option )
question_standard_answer . save
question_standard_answer . save !
end
end
else
@ -323,7 +323,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text = > n
}
question_standard_answer = ExerciseStandardAnswer . new ( standard_option )
question_standard_answer . save
question_standard_answer . save !
end
end
end
@ -340,19 +340,19 @@ class ExerciseQuestionsController < ApplicationController
:answer_text = > main_standard_answer ,
}
question_standard_answer = ExerciseStandardAnswer . new ( standard_option )
question_standard_answer . save
question_standard_answer . save !
end
elsif @exercise_question . question_type == Exercise :: PRACTICAL
question_score = 0
shixun_name = params [ :shixun_name ] || @exercise_question . shixun_name
@exercise_question . exercise_shixun_challenges . each_with_index do | challenge , index |
challenge . question_score = params [ :question_scores ] [ index ] . to_f . round ( 1 )
challenge . save
challenge . save !
question_score += params [ :question_scores ] [ index ] . to_f . round ( 1 )
end
@exercise_question . question_score = question_score
@exercise_question . shixun_name = shixun_name
@exercise_question . save
@exercise_question . save !
end
#当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数.
@ -397,7 +397,7 @@ class ExerciseQuestionsController < ApplicationController
new_objective_score = objective_score + update_objective_score
total_score = ex_user . score + update_objective_score
total_score = total_score < 0 . 0 ? 0 . 0 : total_score
ex_user . update _attributes ( objective_score : new_objective_score , score : total_score )
ex_user . update ! ( objective_score : new_objective_score , score : total_score )
end
end
end
@ -526,7 +526,7 @@ class ExerciseQuestionsController < ApplicationController
:score = > @c_score ,
:answer_text = > " "
}
ExerciseAnswer . create ( answer_option )
ExerciseAnswer . create ! ( answer_option )
ex_answer_old = 0
end
if ex_obj_score < = 0 . 0
@ -545,7 +545,7 @@ class ExerciseQuestionsController < ApplicationController
:objective_score = > new_obj_score ,
:score = > total_scores
}
@exercise_current_user . update _attributes ( ex_scores )
@exercise_current_user . update ! ( ex_scores )
elsif @exercise_question . question_type == Exercise :: COMPLETION #当为填空题,更新问题的总分,
@ -561,7 +561,7 @@ class ExerciseQuestionsController < ApplicationController
:score = > @c_score ,
:answer_text = > " "
}
ExerciseAnswer . create ( answer_option )
ExerciseAnswer . create ! ( answer_option )
new_obj_score = ex_obj_score + @c_score
end
@ -575,7 +575,7 @@ class ExerciseQuestionsController < ApplicationController
:objective_score = > new_obj_score ,
:score = > total_scores
}
@exercise_current_user . update _attributes ( ex_scores )
@exercise_current_user . update ! ( ex_scores )
elsif @exercise_question . question_type == Exercise :: SUBJECTIVE #当为主观题时
if ex_answers . exists?
ex_answers_old_score = ex_answers . first . score > 0 . 0 ? ex_answers . first . score : 0 . 0 #原分数小于0, 取0
@ -588,7 +588,7 @@ class ExerciseQuestionsController < ApplicationController
:score = > @c_score ,
:answer_text = > " "
}
ExerciseAnswer . create ( answer_option )
ExerciseAnswer . create ! ( answer_option )
new_sub_score = ex_subj_score + @c_score
end
total_scores = ex_obj_score + new_sub_score
@ -601,7 +601,7 @@ class ExerciseQuestionsController < ApplicationController
:subjective_score = > new_sub_score ,
:score = > total_scores
}
@exercise_current_user . update _attributes ( ex_scores )
@exercise_current_user . update ! ( ex_scores )
elsif @exercise_question . question_type == Exercise :: PRACTICAL
ex_answers = @exercise_question . exercise_shixun_answers . where ( user_id : @user_id , exercise_shixun_challenge_id : @shixun_a_id )
@ -618,7 +618,7 @@ class ExerciseQuestionsController < ApplicationController
:score = > @c_score ,
:status = > 0
}
ExerciseShixunAnswer . create ( ex_shixun_option )
ExerciseShixunAnswer . create ! ( ex_shixun_option )
new_obj_score = ex_obj_score + @c_score
end
total_scores = new_obj_score + ex_subj_score
@ -631,7 +631,7 @@ class ExerciseQuestionsController < ApplicationController
:objective_score = > new_obj_score ,
:score = > total_scores
}
@exercise_current_user . update _attributes ( ex_scores )
@exercise_current_user . update ! ( ex_scores )
end
comments = params [ :comment ]
question_comment = @exercise_question . exercise_answer_comments & . first
@ -643,7 +643,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_answer_id = > ex_answers . present? ? ex_answers . first . id : nil ,
:user_id = > current_user . id
}
question_comment . update _attributes ( comment_option )
question_comment . update ! ( comment_option )
@exercise_comments = question_comment
else
ex_answer_comment_id = @exercise_question . exercise_answers . find_by ( user_id : @user_id ) . try ( :id )