|
|
|
@ -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
|
|
|
|
|