我创建了一个测验,并且必须使用随机播放随机化要显示的问题,但是当我调用下一个函数来显示下一个问题时。订单再次洗牌我只想要控制器启动之前的洗牌顺序并在该控制器的所有操作中保留它
private
def shuffle(exam_group_id,student_additional_field_id)
questions = Question.find(:all, :conditions => ['exam_group_id=? && student_additional_field_id=?',exam_group_id,student_additional_field_id]).flatten.shuffle
end
在这里我使用下一个功能
class AnswersController < ApplicationController
def start
@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])
@module = params[:student_additional_field]
@questions = shuffle(@exam_group,@module)
@ques = []
@questions.each do |a|
@ques.push a.id unless a.id.nil?
end
a = @ques[0]
@s = 1
@ans = Question.find_by_id(a)
render(:update) do |page|
page.replace_html 'main', :partial => 'ans', :object => @ans
page.replace_html 'quespan', :partial => 'ques'
end
end
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]
unless params[:answer].nil?
@answer.visited = 1
else
@answer.visited = 0
end
@answer.exam_group_id = @exam_group.id
@answer.user_id = @user.id
passed_question = params[:passed_question]
@answer.questions_id = passed_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
@s = 1
@questions = shuffle(@exam_group,student_additional_field_id)
@ques = []
@questions.each do |a|
@ques.push a.id unless a.id.nil?
end
a = @ques[0]
@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 (?)',answered])
@s = @s + answered.count
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
请帮帮我