From 486f0b69b1a4b92cf3836a98e45378081ea0a2a1 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Wed, 31 Dec 2014 10:23:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BF=81=E7=A7=BBstudent=5Ff?= =?UTF-8?q?or=5Fcourse=E7=9A=84=E6=95=B0=E6=8D=AE=20Signed-off-by:=20alan?= =?UTF-8?q?=20<547533434@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 3 +-- ...20141231020031_add_data_to_student_for_course.rb | 13 +++++++++++++ db/schema.rb | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20141231020031_add_data_to_student_for_course.rb diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 83c26b713..07278ec45 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -451,8 +451,7 @@ class HomeworkAttachController < ApplicationController homework.score = @m_score homework.is_teacher_score = 1 else - homework.score = (homework.score.nil? ? 0 : homework.score + @m_score) / homework.rates(:quality).count - + homework.score = homework.rates(:quality).select("avg(stars)") end else if is_teacher == 1 diff --git a/db/migrate/20141231020031_add_data_to_student_for_course.rb b/db/migrate/20141231020031_add_data_to_student_for_course.rb new file mode 100644 index 000000000..a507f907c --- /dev/null +++ b/db/migrate/20141231020031_add_data_to_student_for_course.rb @@ -0,0 +1,13 @@ +class AddDataToStudentForCourse < ActiveRecord::Migration + def change + Course.all.each do |course| + + course.members.each do |m| + if m && m.user && m.user.allowed_to?(:student,course) && StudentsForCourse.find_by_student_id(m.user_id).nil? + StudentsForCourse.create(:student_id => m.user_id, :course_id => course.id) + end + end + + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 528ebdee6..cdd827442 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20141230081744) do +ActiveRecord::Schema.define(:version => 20141231020031) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false