File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments