From 4f8585be428fb18f867413fef6b0fa804bcb5ee6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 25 Jul 2019 14:18:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B=E7=9A=84?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E5=90=8D=E7=A7=B0=E9=99=90=E5=88=B660?= =?UTF-8?q?=E4=B8=AA=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../course_second_categories_controller.rb | 2 +- app/controllers/stages_controller.rb | 11 +++++++---- app/controllers/subjects_controller.rb | 2 +- app/models/stage.rb | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/course_second_categories_controller.rb b/app/controllers/course_second_categories_controller.rb index af368a8dc..e5c3366cd 100644 --- a/app/controllers/course_second_categories_controller.rb +++ b/app/controllers/course_second_categories_controller.rb @@ -8,7 +8,7 @@ class CourseSecondCategoriesController < ApplicationController tip_exception("毕设子目录不能重命名") if @category.category_type == "graduation" tip_exception("名称不能为空") if params[:name].blank? tip_exception("已存在同名子目录") if @course_module.course_second_categories.exists?(name: params[:name].strip) - @category.update_attributes(name: params[:name].strip) + @category.update_attributes!(name: params[:name].strip) normal_status(0, "更新成功") end diff --git a/app/controllers/stages_controller.rb b/app/controllers/stages_controller.rb index c62832365..d456c17e7 100644 --- a/app/controllers/stages_controller.rb +++ b/app/controllers/stages_controller.rb @@ -39,10 +39,13 @@ class StagesController < ApplicationController def update ActiveRecord::Base.transaction do begin - @stage.update_attributes(stage_params) - @stage.stage_shixuns.destroy_all + @stage.update_attributes!(stage_params) unless params[:shixun_id].blank? - params[:shixun_id].each do |shixun_id| + new_shixun_ids = params[:shixun_id] - @stage.stage_shixuns.pluck(:shixun_id) + delete_shixun_ids = @stage.stage_shixuns.pluck(:shixun_id) - params[:shixun_id] + @stage.stage_shixuns.where(shixun_id: delete_shixun_ids).destroy_all + + new_shixun_ids.each do |shixun_id| shixun = Shixun.where(id: shixun_id).first @stage.stage_shixuns.create!(subject_id: @subject.id, shixun_id: shixun.id, position: @stage.stage_shixuns.count + 1) if shixun.present? end @@ -50,7 +53,7 @@ class StagesController < ApplicationController @subject.update_attributes(updated_at: Time.now) rescue Exception => e uid_logger_error(e.message) - tip_exception("章节更新失败") + tip_exception(e.message) raise ActiveRecord::Rollback end end diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index cc0e06a38..5cbb2a462 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -207,7 +207,7 @@ class SubjectsController < ApplicationController end rescue Exception => e uid_logger(e.message) - tip_exception("发送失败") + tip_exception(e.message) raise ActiveRecord::Rollback end end diff --git a/app/models/stage.rb b/app/models/stage.rb index d255cddeb..db7b5c0b3 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -6,6 +6,6 @@ class Stage < ApplicationRecord has_many :stage_shixuns, -> { order("stage_shixuns.position ASC") }, dependent: :destroy has_many :shixuns, :through => :stage_shixuns - validates :name, length: { maximum: 30 } + validates :name, length: { maximum: 60 } validates :description, length: { maximum: 300 } end