From b0b056ebc35f2fed4015945baadac228f79fa941 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 25 Jul 2019 14:23:02 +0800 Subject: [PATCH] stage update --- app/controllers/stages_controller.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/controllers/stages_controller.rb b/app/controllers/stages_controller.rb index d456c17e7..3967554aa 100644 --- a/app/controllers/stages_controller.rb +++ b/app/controllers/stages_controller.rb @@ -40,12 +40,9 @@ class StagesController < ApplicationController ActiveRecord::Base.transaction do begin @stage.update_attributes!(stage_params) + @stage.stage_shixuns.destroy_all unless params[:shixun_id].blank? - 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| + params[:shixun_id].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