Description:
fixed problem insertion attribute error
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r775:3d1a060b0378 - - 1 file changed: 5 inserted, 1 deleted

@@ -1,80 +1,80
1 1 class ProblemsController < ApplicationController
2 2
3 3 before_action :authenticate, :authorization
4 4 before_action :testcase_authorization, only: [:show_testcase]
5 5
6 6 in_place_edit_for :problem, :name
7 7 in_place_edit_for :problem, :full_name
8 8 in_place_edit_for :problem, :full_score
9 9
10 10 def index
11 11 @problems = Problem.order(date_added: :desc)
12 12 end
13 13
14 14 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15 15 verify :method => :post, :only => [ :create, :quick_create,
16 16 :do_manage,
17 17 :do_import,
18 18 ],
19 19 :redirect_to => { :action => :index }
20 20
21 21 def show
22 22 @problem = Problem.find(params[:id])
23 23 end
24 24
25 25 def new
26 26 @problem = Problem.new
27 27 @description = nil
28 28 end
29 29
30 30 def create
31 31 @problem = Problem.new(problem_params)
32 - @description = Description.new(params[:description])
32 + @description = Description.new(description_params)
33 33 if @description.body!=''
34 34 if !@description.save
35 35 render :action => new and return
36 36 end
37 37 else
38 38 @description = nil
39 39 end
40 40 @problem.description = @description
41 41 if @problem.save
42 42 flash[:notice] = 'Problem was successfully created.'
43 43 redirect_to action: :index
44 44 else
45 45 render :action => 'new'
46 46 end
47 47 end
48 48
49 49 def quick_create
50 50 @problem = Problem.new(problem_params)
51 51 @problem.full_name = @problem.name if @problem.full_name == ''
52 52 @problem.full_score = 100
53 53 @problem.available = false
54 54 @problem.test_allowed = true
55 55 @problem.output_only = false
56 56 @problem.date_added = Time.new
57 57 if @problem.save
58 58 flash[:notice] = 'Problem was successfully created.'
59 59 redirect_to action: :index
60 60 else
61 61 flash[:notice] = 'Error saving problem'
62 62 redirect_to action: :index
63 63 end
64 64 end
65 65
66 66 def edit
67 67 @problem = Problem.find(params[:id])
68 68 @description = @problem.description
69 69 end
70 70
71 71 def update
72 72 @problem = Problem.find(params[:id])
73 73 @description = @problem.description
74 74 if @description.nil? and params[:description][:body]!=''
75 75 @description = Description.new(params[:description])
76 76 if !@description.save
77 77 flash[:notice] = 'Error saving description'
78 78 render :action => 'edit' and return
79 79 end
80 80 @problem.description = @description
@@ -207,96 +207,100
207 207 failed << p.full_name
208 208 end
209 209 end
210 210 flash[:success] = "The following problems are added to the group #{group.name}: " + ok.join(', ') if ok.count > 0
211 211 flash[:alert] = "The following problems are already in the group #{group.name}: " + failed.join(', ') if failed.count > 0
212 212 elsif params.has_key? 'add_tags'
213 213 get_problems_from_params.each do |p|
214 214 p.tag_ids += params[:tag_ids]
215 215 end
216 216 end
217 217
218 218 redirect_to :action => 'manage'
219 219 end
220 220
221 221 def import
222 222 @allow_test_pair_import = allow_test_pair_import?
223 223 end
224 224
225 225 def do_import
226 226 old_problem = Problem.find_by_name(params[:name])
227 227 if !allow_test_pair_import? and params.has_key? :import_to_db
228 228 params.delete :import_to_db
229 229 end
230 230 @problem, import_log = Problem.create_from_import_form_params(params,
231 231 old_problem)
232 232
233 233 if !@problem.errors.empty?
234 234 render :action => 'import' and return
235 235 end
236 236
237 237 if old_problem!=nil
238 238 flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
239 239 end
240 240 @log = import_log
241 241 end
242 242
243 243 def remove_contest
244 244 problem = Problem.find(params[:id])
245 245 contest = Contest.find(params[:contest_id])
246 246 if problem!=nil and contest!=nil
247 247 problem.contests.delete(contest)
248 248 end
249 249 redirect_to :action => 'manage'
250 250 end
251 251
252 252 ##################################
253 253 protected
254 254
255 + def description_params
256 + params.require(:description).permit(:body, :markdowned)
257 + end
258 +
255 259 def allow_test_pair_import?
256 260 if defined? ALLOW_TEST_PAIR_IMPORT
257 261 return ALLOW_TEST_PAIR_IMPORT
258 262 else
259 263 return false
260 264 end
261 265 end
262 266
263 267 def change_date_added
264 268 problems = get_problems_from_params
265 269 date = Date.parse(params[:date_added])
266 270 problems.each do |p|
267 271 p.date_added = date
268 272 p.save
269 273 end
270 274 end
271 275
272 276 def add_to_contest
273 277 problems = get_problems_from_params
274 278 contest = Contest.find(params[:contest][:id])
275 279 if contest!=nil and contest.enabled
276 280 problems.each do |p|
277 281 p.contests << contest
278 282 end
279 283 end
280 284 end
281 285
282 286 def set_available(avail)
283 287 problems = get_problems_from_params
284 288 problems.each do |p|
285 289 p.available = avail
286 290 p.save
287 291 end
288 292 end
289 293
290 294 def get_problems_from_params
291 295 problems = []
292 296 params.keys.each do |k|
293 297 if k.index('prob-')==0
294 298 name, id, order = k.split('-')
295 299 problems << Problem.find(id)
296 300 end
297 301 end
298 302 problems
299 303 end
300 304
301 305 def get_problems_stat
302 306 end
You need to be logged in to leave comments. Login now