Description:
update errors.add_to_base("x") to Rails 3 errors.add(:base,"x")
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r347:6d2339b98fac - - 6 files changed: 12 inserted, 12 deleted

@@ -60,25 +60,25
60 60
61 61 @submission = Submission.new
62 62 @submission.problem_id = params[:submission][:problem_id]
63 63 @submission.user = user
64 64 @submission.language_id = 0
65 65 if (params['file']) and (params['file']!='')
66 66 @submission.source = params['file'].read
67 67 @submission.source_filename = params['file'].original_filename
68 68 end
69 69 @submission.submitted_at = Time.new.gmtime
70 70
71 71 if GraderConfiguration.time_limit_mode? and user.contest_finished?
72 - @submission.errors.add_to_base "The contest is over."
72 + @submission.errors.add(:base,"The contest is over.")
73 73 prepare_list_information
74 74 render :action => 'list' and return
75 75 end
76 76
77 77 if @submission.valid?
78 78 if @submission.save == false
79 79 flash[:notice] = 'Error saving your submission'
80 80 elsif Task.create(:submission_id => @submission.id,
81 81 :status => Task::STATUS_INQUEUE) == false
82 82 flash[:notice] = 'Error adding your submission to task queue'
83 83 end
84 84 else
@@ -17,25 +17,25
17 17 def submit
18 18 @user = User.find(session[:user_id])
19 19
20 20 @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request])
21 21
22 22 if ! @submitted_test_request.errors.empty?
23 23 prepare_index_information
24 24 render :action => 'index' and return
25 25 end
26 26
27 27 if GraderConfiguration.time_limit_mode?
28 28 if @user.contest_finished?
29 - @submitted_test_request.errors.add_to_base('Contest is over.')
29 + @submitted_test_request.errors.add(:base,'Contest is over.')
30 30 prepare_index_information
31 31 render :action => 'index' and return
32 32 end
33 33
34 34 if !GraderConfiguration.allow_test_request(@user)
35 35 prepare_index_information
36 36 flash[:notice] = 'Test request is not allowed during the last 30 minutes'
37 37 redirect_to :action => 'index' and return
38 38 end
39 39 end
40 40
41 41 if @submitted_test_request.save
@@ -53,25 +53,25
53 53 end
54 54 @user = User.new(params[:user])
55 55 @user.password_confirmation = @user.password = User.random_password
56 56 @user.activated = false
57 57 if (@user.valid?) and (@user.save)
58 58 if send_confirmation_email(@user)
59 59 render :action => 'new_splash', :layout => 'empty'
60 60 else
61 61 @admin_email = GraderConfiguration['system.admin_email']
62 62 render :action => 'email_error', :layout => 'empty'
63 63 end
64 64 else
65 - @user.errors.add_to_base("Email cannot be blank") if @user.email==''
65 + @user.errors.add(:base,"Email cannot be blank") if @user.email==''
66 66 render :action => 'new', :layout => 'empty'
67 67 end
68 68 end
69 69
70 70 def confirm
71 71 login = params[:login]
72 72 key = params[:activation]
73 73 @user = User.find_by_login(login)
74 74 if (@user) and (@user.verify_activation_key(key))
75 75 if @user.valid? # check uniquenss of email
76 76 @user.activated = true
77 77 @user.save
@@ -35,25 +35,25
35 35 if not problem.save
36 36 return problem, 'Error importing'
37 37 end
38 38
39 39 import_to_db = params.has_key? :import_to_db
40 40
41 41 importer = TestdataImporter.new(problem)
42 42
43 43 if not importer.import_from_file(import_params[:file],
44 44 import_params[:time_limit],
45 45 import_params[:memory_limit],
46 46 import_to_db)
47 - problem.errors.add_to_base('Import error.')
47 + problem.errors.add(:base,'Import error.')
48 48 end
49 49
50 50 return problem, importer.log_msg
51 51 end
52 52
53 53 def self.download_file_basedir
54 54 return "#{Rails.root}/data/tasks"
55 55 end
56 56
57 57 protected
58 58
59 59 def self.to_i_or_default(st, default)
@@ -68,35 +68,35
68 68 result = st.to_f
69 69 end
70 70 result ||= default
71 71 end
72 72
73 73 def self.extract_params_and_check(params, problem)
74 74 time_limit = Problem.to_f_or_default(params[:time_limit],
75 75 DEFAULT_TIME_LIMIT)
76 76 memory_limit = Problem.to_i_or_default(params[:memory_limit],
77 77 DEFAULT_MEMORY_LIMIT)
78 78
79 79 if time_limit<=0 or time_limit >60
80 - problem.errors.add_to_base('Time limit out of range.')
80 + problem.errors.add(:base,'Time limit out of range.')
81 81 end
82 82
83 83 if memory_limit==0 and params[:memory_limit]!='0'
84 - problem.errors.add_to_base('Memory limit format errors.')
84 + problem.errors.add(:base,'Memory limit format errors.')
85 85 elsif memory_limit<=0 or memory_limit >512
86 - problem.errors.add_to_base('Memory limit out of range.')
86 + problem.errors.add(:base,'Memory limit out of range.')
87 87 end
88 88
89 89 if params[:file]==nil or params[:file]==''
90 - problem.errors.add_to_base('No testdata file.')
90 + problem.errors.add(:base,'No testdata file.')
91 91 end
92 92
93 93 file = params[:file]
94 94
95 95 if !problem.errors.empty?
96 96 return nil, problem
97 97 end
98 98
99 99 problem.name = params[:name]
100 100 if params[:full_name]!=''
101 101 problem.full_name = params[:full_name]
102 102 else
@@ -61,30 +61,30
61 61 test_request.problem = problem
62 62 if problem!=nil
63 63 test_request.submission =
64 64 Submission.find_by_user_problem_number(user.id,
65 65 problem.id,
66 66 params[:submission_number])
67 67 else
68 68 test_request.submission = nil
69 69 end
70 70
71 71 # checks if the user submits any input file
72 72 if params[:input_file]==nil or params[:input_file]==""
73 - test_request.errors.add_to_base("No input submitted.")
73 + test_request.errors.add(:base,"No input submitted.")
74 74 test_request.input_file_name = nil
75 75 else
76 76 test_request.input_file_name = save_input_file(params[:input_file], user, problem)
77 77 if test_request.input_file_name == nil
78 - test_request.errors.add_to_base("No input submitted.")
78 + test_request.errors.adds(:base,"No input submitted.")
79 79 end
80 80 if params[:additional_file]!=nil and params[:additional_file]!=""
81 81 save_additional_file(params[:additional_file],
82 82 "#{test_request.input_file_name}.files")
83 83 end
84 84 end
85 85 test_request.submitted_at = Time.new.gmtime
86 86 test_request.status_inqueue
87 87 test_request
88 88 end
89 89
90 90 protected
@@ -289,35 +289,35
289 289
290 290 def password_required?
291 291 self.hashed_password.blank? || !self.password.blank?
292 292 end
293 293
294 294 def self.encrypt(string,salt)
295 295 Digest::SHA1.hexdigest(salt + string)
296 296 end
297 297
298 298 def uniqueness_of_email_from_activated_users
299 299 user = User.activated_users.find_by_email(self.email)
300 300 if user and (user.login != self.login)
301 - self.errors.add_to_base("Email has already been taken")
301 + self.errors.add(:base,"Email has already been taken")
302 302 end
303 303 end
304 304
305 305 def enough_time_interval_between_same_email_registrations
306 306 return if !self.new_record?
307 307 return if self.activated
308 308 open_user = User.find_by_email(self.email,
309 309 :order => 'created_at DESC')
310 310 if open_user and open_user.created_at and
311 311 (open_user.created_at > Time.now.gmtime - 5.minutes)
312 - self.errors.add_to_base("There are already unactivated registrations with this e-mail address (please wait for 5 minutes)")
312 + self.errors.add(:base,"There are already unactivated registrations with this e-mail address (please wait for 5 minutes)")
313 313 end
314 314 end
315 315
316 316 def email_validation?
317 317 begin
318 318 return VALIDATE_USER_EMAILS
319 319 rescue
320 320 return false
321 321 end
322 322 end
323 323 end
You need to be logged in to leave comments. Login now