diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index a429a8397..911df776e 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -695,7 +695,7 @@ class AttachmentsController < ApplicationController @attachment.container.board.course) @course = @attachment.container.board.course else - unless @attachment.container_type == 'Syllabus' || @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' || @attachment.container_type == 'Work'|| @attachment.container_type == 'ContestantWork'|| @attachment.container_type == 'Contest' + unless @attachment.container_type == 'Syllabus' || @attachment.container_type == 'Bid' || @attachment.container_type == 'Organization' || @attachment.container_type == 'HomeworkAttach' || @attachment.container_type == 'Memo' || @attachment.container_type == 'Softapplication' || @attachment.container_type == 'PhoneAppVersion' || @attachment.container_type == 'StudentWorksScore'|| @attachment.container_type == 'StudentWork' || @attachment.container_type == 'Work'|| @attachment.container_type == 'ContestantWork'|| @attachment.container_type == 'Contest' || @attachment.container_type == 'HomeworkBank' @project = @attachment.project end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 186dc36ed..5fc83a93e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1269,14 +1269,14 @@ class UsersController < ApplicationController #@homework.end_time = homework.end_time @homework.homework_type = homework.homework_type #@homework.course_id = homework.course_id - # homework.attachments.each do |attachment| - # att = attachment.copy - # att.container_id = nil - # att.container_type = nil - # att.copy_from = attachment.id - # att.save - # @homework.attachments << att - # end + homework.attachments.each do |attachment| + att = attachment.copy + att.container_id = nil + att.container_type = nil + att.copy_from = attachment.id + att.save + @homework.attachments << att + end #if homework_detail_programing if homework.homework_type == 2 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d668a4764..0ddca7032 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2532,6 +2532,8 @@ module ApplicationHelper candown = true elsif attachment.container.class.to_s=="ContestantWork" candown = true + elsif attachment.container.class.to_s=="HomeworkBank" + candown = true elsif attachment.container.class.to_s=="BlogComment" #博客资源允许下载 candown = true elsif attachment.container.class.to_s=="Memo" #论坛资源允许下载 @@ -4149,6 +4151,15 @@ def add_to_homework_bank_f homework homework_bank.max_num = homework.homework_detail_group.max_num homework_bank.base_on_project = homework.homework_detail_group.base_on_project end + homework.attachments.each do |attachment| + att = attachment.copy + att.container_id = nil + att.container_type = nil + att.author_id = homework_bank.user_id + att.copy_from = attachment.id + att.save + homework_bank.attachments << att + end homework_bank end diff --git a/app/views/users/_homework_repository_detail.html.erb b/app/views/users/_homework_repository_detail.html.erb index 0d7bb9f26..27cd7ffcb 100644 --- a/app/views/users/_homework_repository_detail.html.erb +++ b/app/views/users/_homework_repository_detail.html.erb @@ -65,6 +65,10 @@ 分组人数:<%=@homework.min_num %> - <%=@homework.max_num %>人

<% end %> + +
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => @homework} %> +
diff --git a/db/migrate/20170227074837_add_attach_to_homework_bank.rb b/db/migrate/20170227074837_add_attach_to_homework_bank.rb new file mode 100644 index 000000000..1fff0d7d9 --- /dev/null +++ b/db/migrate/20170227074837_add_attach_to_homework_bank.rb @@ -0,0 +1,19 @@ +class AddAttachToHomeworkBank < ActiveRecord::Migration + def change + HomeworkBank.all.each do |homework_bank| + homework = homework_bank.homework_common_id.nil? ? nil : HomeworkCommon.where(:id =>homework_bank.homework_common_id).first + unless homework.nil? + homework.attachments.each do |attachment| + att = attachment.copy + att.container_id = nil + att.container_type = nil + att.author_id = homework_bank.user_id + att.copy_from = attachment.id + att.save + homework_bank.attachments << att + homework_bank.save + end + end + end + end +end