From 388d14f0756aea30830a8345a386452928bfc728 Mon Sep 17 00:00:00 2001 From: nwb Date: Fri, 6 Jun 2014 08:50:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=AF=BE=E7=A8=8B=E5=8E=9F?= =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=8C=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 1 + app/models/journals_for_message.rb | 5 +++++ .../20140606027403_migrate_course_journals.rb | 15 +++++++++++++++ db/schema.rb | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20140606027403_migrate_course_journals.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 4036d637e..335426bf7 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,5 +1,6 @@ class CoursesController < ApplicationController include CoursesHelper + helper :activities menu_item l(:label_sort_by_time), :only => :index menu_item l(:label_sort_by_active), :only => :index diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 7356b7373..584057d10 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -18,6 +18,9 @@ class JournalsForMessage < ActiveRecord::Base belongs_to :project, :foreign_key => 'jour_id', :conditions => "#{self.table_name}.jour_type = 'Project' " + belongs_to :course, + :foreign_key => 'jour_id', + :conditions => "#{self.table_name}.jour_type = 'Course' " belongs_to :jour, :polymorphic => true belongs_to :user @@ -87,6 +90,8 @@ class JournalsForMessage < ActiveRecord::Base end elsif self.jour_type == 'Project' self.acts << Activity.new(:user_id => self.reply_id) + elsif self.jour_type == 'Course' + self.acts << Activity.new(:user_id => self.reply_id) else end end diff --git a/db/migrate/20140606027403_migrate_course_journals.rb b/db/migrate/20140606027403_migrate_course_journals.rb new file mode 100644 index 000000000..44b3e562c --- /dev/null +++ b/db/migrate/20140606027403_migrate_course_journals.rb @@ -0,0 +1,15 @@ +class MigrateCourseJournals < ActiveRecord::Migration + def self.up + # 原课程的讨论区数据迁移成新模式 + JournalsForMessage.find_all_by_jour_type('Project').each do |journal| + project = Project.find_by_id(journal.jour_id) + if project && project.project_type == 1 + journal.jour_type = 'Course' + journal.save + end + end + end + + def self.down + end +end diff --git a/db/schema.rb b/db/schema.rb index f642770a0..2ad745f56 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 => 20140605025303) do +ActiveRecord::Schema.define(:version => 20140606027403) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false