Skip to content

Commit 962e311

Browse files
committed
Fix contest problem reordering
1 parent 447a007 commit 962e311

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

app/controllers/contests_controller.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,23 @@ def update
164164
if !tasks_valid?
165165
format.html { render action: 'edit' }
166166
format.json { render json: @contest.errors, status: :unprocessable_entity }
167-
elsif @contest.update(contest_params)
168-
format.html { redirect_to @contest, notice: 'Contest was successfully updated.' }
169-
format.json { head :no_content }
170167
else
171-
format.html { render action: 'edit' }
172-
format.json { render json: @contest.errors, status: :unprocessable_entity }
168+
begin
169+
ret = @contest.update(contest_params)
170+
rescue ActiveRecord::RecordNotUnique
171+
params[:contest][:contest_problem_joints_attributes].each {|key, val| val.delete(:id)}
172+
ActiveRecord::Base.transaction do
173+
@contest.contest_problem_joints.destroy_all()
174+
ret = @contest.update(contest_params)
175+
end
176+
end
177+
if ret
178+
format.html { redirect_to @contest, notice: 'Contest was successfully updated.' }
179+
format.json { head :no_content }
180+
else
181+
format.html { render action: 'edit' }
182+
format.json { render json: @contest.errors, status: :unprocessable_entity }
183+
end
173184
end
174185
end
175186
end

0 commit comments

Comments
 (0)