diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index cea5f0f77..dd54e2aae 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -43,8 +43,6 @@ class AttachmentsController < ApplicationController local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) content_type = upload_file.content_type.presence || 'application/octet-stream' - container_id = upload_file.container_id. - container_tpe = upload_file.container_id # remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端 @@ -70,9 +68,9 @@ class AttachmentsController < ApplicationController @attachment.author_id = current_user.id @attachment.disk_directory = month_folder @attachment.cloud_url = remote_path - @attachment.container_id = upload_file.container_id - @attachment.container_type = upload_file.container_type - @attachment.attachtype = upload_file.attachtype + @attachment.container_id = params[:container_id] + @attachment.container_type = params[:container_type] + @attachment.attachtype = params[:attachtype] @attachment.save! else logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" diff --git a/db/migrate/20191211025413_add_index_for_shixun_secret_repositories.rb b/db/migrate/20191211025413_add_index_for_shixun_secret_repositories.rb new file mode 100644 index 000000000..650b821e1 --- /dev/null +++ b/db/migrate/20191211025413_add_index_for_shixun_secret_repositories.rb @@ -0,0 +1,17 @@ +class AddIndexForShixunSecretRepositories < ActiveRecord::Migration[5.2] + def change + shixun_ids = ShixunSecretRepository.pluck(:shixun_id).uniq + shixuns = Shixun.where(id: shixun_ids) + shixuns.find_each do |shixun| + id = shixun.shixun_secret_repository.id + shixun_secret_repositories = ShixunSecretRepository.where(shixun_id: shixun.id).where.not(id: id) + shixun_secret_repositories.destroy_all + end + + remove_index :shixun_secret_repositories, :shixun_id + add_index :shixun_secret_repositories, :shixun_id, unique: true + + + + end +end