|
|
@ -39,10 +39,13 @@ class StagesController < ApplicationController
|
|
|
|
def update
|
|
|
|
def update
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
@stage.update_attributes(stage_params)
|
|
|
|
@stage.update_attributes!(stage_params)
|
|
|
|
@stage.stage_shixuns.destroy_all
|
|
|
|
|
|
|
|
unless params[:shixun_id].blank?
|
|
|
|
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
|
|
|
|
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?
|
|
|
|
@stage.stage_shixuns.create!(subject_id: @subject.id, shixun_id: shixun.id, position: @stage.stage_shixuns.count + 1) if shixun.present?
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -50,7 +53,7 @@ class StagesController < ApplicationController
|
|
|
|
@subject.update_attributes(updated_at: Time.now)
|
|
|
|
@subject.update_attributes(updated_at: Time.now)
|
|
|
|
rescue Exception => e
|
|
|
|
rescue Exception => e
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
tip_exception("章节更新失败")
|
|
|
|
tip_exception(e.message)
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|