我创建了一个测验,并且每页显示一个项目。我想要当前用户访问的问题 id 的值。在这段代码中,我接下来给出了我希望当前用户访问的问题 id 的问题
def next
@user = current_user
@student = Student.find_by_admission_no(@user.username)
@exam_group = ExamGroup.find_by_id(params[:exam_group_id])
@answer = Answer.new(params[:ans])
@answer.answer = params[:answer]
@answer.exam_group_id = @exam_group.id
@answer.user_id = @user.id
passed_question = params[:passed_question]
@answer.questions_id = passed_question
next_question = params[:next_question]
@question = Question.find_by_id(passed_question)
@module = Question.find_by_sql ["SELECT student_additional_field_id FROM questions WHERE id=#{passed_question}"]
student_additional_field_id = @module[0].student_additional_field_id
@questions = Question.find(:all, :conditions => [' exam_group_id=? && student_additional_field_id=? ',@exam_group,student_additional_field_id], :offset => @ans)
@ques = []
@questions.shuffle.each do |a|
@ques.push a.id unless a.id.nil?
end
a = @ques[0]
session[:ques_id] = a
@answer.modules_id = student_additional_field_id
if params[:answer] == @question.is_answer
@answer.marks = 1
else
@answer.marks = 0
end
if @answer.save
@ans = Question.find_by_id(a, :conditions => [' id not in (?) && exam_group_id=?',answered, @exam_group])
unless @ans.nil?
render(:update) do |page|
page.replace_html 'main', :partial => 'ans', :object => @ans
end
else
render(:update) do |page|
page.replace_html 'main', :partial => 'ans2'
end
end
end
end