From cd3c69af9406db118a21c4dcf2e709dd9e2feae3 Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 5 Jun 2014 14:07:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=BF=81=E7=A7=BB=EF=BC=8C=E4=BB=8E=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=B8=AD=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment.rb | 1 + app/views/layouts/base_courses.html.erb | 7 ++----- ...20140605025302_migrate_course_attachments.rb | 17 +++++++++++++++++ db/schema.rb | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20140605025302_migrate_course_attachments.rb diff --git a/app/models/attachment.rb b/app/models/attachment.rb index aff63439e..65e3fe26a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -21,6 +21,7 @@ require "fileutils" class Attachment < ActiveRecord::Base belongs_to :container, :polymorphic => true belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'" + belongs_to :course, foreign_key: 'container_id', conditions: "attachments.container_type = 'Course'" belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'" belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id" diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index e4a52826b..73c46b68b 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -40,9 +40,9 @@ - <%= link_to request.host()+"/course", :controller => 'courses', :action => 'course' %> + <%= link_to request.host()+"/course", :controller => 'courses', :action => 'index' %>

<%= link_to "主页", home_path %> - > <%= link_to l(:label_course_practice), :controller => 'courses', :action => 'course' %> + > <%= link_to l(:label_course_practice), :controller => 'courses', :action => 'index' %> > <%= link_to @course.name, nil %>

@@ -79,9 +79,6 @@ <% end %> <% unless User.current.member_of?(@course) %> -
- - <%= watcher_link(@course, User.current) %>
<% end %> <% end %> diff --git a/db/migrate/20140605025302_migrate_course_attachments.rb b/db/migrate/20140605025302_migrate_course_attachments.rb new file mode 100644 index 000000000..447624fa4 --- /dev/null +++ b/db/migrate/20140605025302_migrate_course_attachments.rb @@ -0,0 +1,17 @@ +class MigrateCourseAttachments < ActiveRecord::Migration + def self.up + # 原课程的资源数据迁移成新模式 + Attachment.all.each do |attach| + if attach.container_type == "Project" + project = Project.find_by_id(attach.container_id) + if project && project.project_type == 1 + attach.container_type= 'Course' + attach.save + end + end + end + end + + def self.down + end +end diff --git a/db/schema.rb b/db/schema.rb index dae888700..d559d41fb 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 => 20140605025300) do +ActiveRecord::Schema.define(:version => 20140605025302) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false