У меня вопрос по этому поводу:
@st = exam.students.find(:all)
@st.each do |student|
Верните мне массив со всеми студентами, но:
exam.students.each do |student|
Верните мне массив с 4-мя учениками
Вот печать
печать
У кого-нибудь есть идеи по этому поводу?
UPDATE:
Вот моя модель экзамена:
set_table_name "exam"
set_primary_key "ID_Exam"
belongs_to :questionnaire, :foreign_key => "ID_Questionnaire"
has_many :responses, :foreign_key => "ID_Exam"
has_many :students, :through => :responses, :foreign_key => "ID_Exam", :group => "response.ID_Student"
belongs_to :professor, :foreign_key => "ID_Professor"
has_many :student_exam_times
has_many :exam_halted_students
has_many :exam_paused_students
has_many :answered_questions
А это мой ученик Модель:
set_table_name "student"
set_primary_key "ID_Student"
has_one :user, :foreign_key => "ID_User"
has_many :group_student, :foreign_key => "ID_Student", :group => "group_student.ID_Group"
has_many :groups, :through => :group_student, :foreign_key => "ID_Group"
has_many :responses, :foreign_key => "ID_Student"
has_many :exams, :through => :responses, :foreign_key => "ID_Exam", :group => "exam.ID_Exam"
has_many :student_exam_times
has_many :exam_halted_students
has_many :exam_paused_students
has_many :marked_questions
has_many :answered_questions
has_many :messages, :order => "viewed ASC, send_at DESC"
ОБНОВЛЕНИЕ 2:
Вот мой блок:
students_exam = exam.students.find(:all)
students_exam.each do |student|
cont=StudentExamTime.find(:first,:conditions => {:student_id => student.id, :exam_id => params[:exam_id].to_i })
bd_time=0
if cont==nil
cont=StudentExamTime.new
else
bd_time=cont.time
end
cont.student_id=student.id
cont.exam_id=params[:exam_id].to_i
cont.time=bd_time + params[:time].to_i
cont.save
end