课程资源文件迁移,从项目中分离

This commit is contained in:
nwb 2014-06-05 14:07:44 +08:00
parent 6ff26d06ab
commit cd3c69af94
4 changed files with 21 additions and 6 deletions

View File

@ -21,6 +21,7 @@ require "fileutils"
class Attachment < ActiveRecord::Base class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true belongs_to :container, :polymorphic => true
belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'" 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 :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :author, :class_name => "User", :foreign_key => "author_id"
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id" belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"

View File

@ -40,9 +40,9 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td style="padding-left: 8px"><%= link_to request.host()+"/course", :controller => 'courses', :action => 'course' %></td> <td style="padding-left: 8px"><%= link_to request.host()+"/course", :controller => 'courses', :action => 'index' %></td>
<td><p class="top-content-list"><%= link_to "主页", home_path %> <td><p class="top-content-list"><%= 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 %></p></td> > <%= link_to @course.name, nil %></p></td>
</tr> </tr>
</table> </table>
@ -79,9 +79,6 @@
<% end %> <% end %>
<% unless User.current.member_of?(@course) %> <% unless User.current.member_of?(@course) %>
<!-- <%= image_tag "/images/fav.png" %> --> <!-- <%= image_tag "/images/fav.png" %> -->
<div style="padding-right: 10px">
<span class="icon-fav icon"></span><span>
<%= watcher_link(@course, User.current) %></span></div>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>

View File

@ -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

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false