From 259799eb89366bcb3f89d3e8badb91f202363b95 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Mon, 29 Dec 2014 11:38:35 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E8=AF=84=E5=88=86=E7=9A=84?= =?UTF-8?q?model=202.=E4=BF=AE=E6=94=B9=E8=AF=84=E5=88=86=E8=A1=A8?= =?UTF-8?q?=E4=B8=AD=E4=B8=BA=E6=95=99=E5=B8=88=E8=AF=84=E5=88=86=E7=9A=84?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E7=9A=84is=5Fteacher=5Fsco?= =?UTF-8?q?re=E7=9A=84=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/seems_rateable_rates.rb | 3 +++ ...41229025925_change_seems_rateable_rates.rb | 23 +++++++++++++++++++ db/schema.rb | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/models/seems_rateable_rates.rb create mode 100644 db/migrate/20141229025925_change_seems_rateable_rates.rb diff --git a/app/models/seems_rateable_rates.rb b/app/models/seems_rateable_rates.rb new file mode 100644 index 000000000..664f987ba --- /dev/null +++ b/app/models/seems_rateable_rates.rb @@ -0,0 +1,3 @@ +class SeemsRateableRates < ActiveRecord::Base + attr_accessible :rater_id, :rateable_id, :rateable_type, :stars, :dimension, :is_teacher_score +end diff --git a/db/migrate/20141229025925_change_seems_rateable_rates.rb b/db/migrate/20141229025925_change_seems_rateable_rates.rb new file mode 100644 index 000000000..9ea75e68e --- /dev/null +++ b/db/migrate/20141229025925_change_seems_rateable_rates.rb @@ -0,0 +1,23 @@ +class ChangeSeemsRateableRates < ActiveRecord::Migration + def up + SeemsRateableRates.where("rateable_type = 'HomeworkAttach'").each do |rate| + homework = HomeworkAttach.find_by_id rate.rateable_id + if homework + course = homework.bid.courses.first + if course + teachers = [] + course.members.each do |m| + teachers << m.user_id if m && m.user && m.user.allowed_to?(:as_teacher,course) + end + if teachers.include?(rate.rater_id) + rate.is_teacher_score = 1 + rate.save + end + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index e109212cc..5725d8221 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 => 20141229025519) do +ActiveRecord::Schema.define(:version => 20141229025925) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false