|
|
|
@ -15,8 +15,18 @@ class Competitions::CompetitionModulesController < Competitions::BaseController
|
|
|
|
|
md = current_module.competition_module_md_content || current_module.build_competition_module_md_content
|
|
|
|
|
md.name = params[:md_name]
|
|
|
|
|
md.content = params[:md_content]
|
|
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
md.save!
|
|
|
|
|
|
|
|
|
|
attachment_ids = Array.wrap(params[:attachment_ids]).map(&:to_i)
|
|
|
|
|
old_attachment_ids = md.attachments.pluck(:id)
|
|
|
|
|
|
|
|
|
|
destroy_ids = old_attachment_ids - attachment_ids
|
|
|
|
|
md.attachments.where(id: destroy_ids).delete_all
|
|
|
|
|
Attachment.where(id: attachment_ids - old_attachment_ids).update_all(container: md)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|