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