Description:
fix some layout problem: first time at main after login, using wrong layouts git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@39 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r15:ef7a1ef3afd0 - - 1 file changed: 2 inserted, 0 deleted

@@ -1,55 +1,57
1 class MainController < ApplicationController
1 class MainController < ApplicationController
2
2
3 before_filter :authenticate, :except => [:index, :login]
3 before_filter :authenticate, :except => [:index, :login]
4
4
5 verify :method => :post, :only => [:submit],
5 verify :method => :post, :only => [:submit],
6 :redirect_to => { :action => :index }
6 :redirect_to => { :action => :index }
7
7
8 + layout 'application'
9 +
8 def index
10 def index
9 redirect_to :action => 'login'
11 redirect_to :action => 'login'
10 end
12 end
11
13
12 def login
14 def login
13 MainController.layout 'login'
15 MainController.layout 'login'
14 reset_session
16 reset_session
15 end
17 end
16
18
17 def list
19 def list
18 @problems = Problem.find_available_problems
20 @problems = Problem.find_available_problems
19 @prob_submissions = Array.new
21 @prob_submissions = Array.new
20 @user = User.find(session[:user_id])
22 @user = User.find(session[:user_id])
21 @problems.each do |p|
23 @problems.each do |p|
22 c, sub = Submission.find_by_user_and_problem(@user.id,p.id)
24 c, sub = Submission.find_by_user_and_problem(@user.id,p.id)
23 @prob_submissions << [c,sub]
25 @prob_submissions << [c,sub]
24 end
26 end
25 end
27 end
26
28
27 def submit
29 def submit
28 submission = Submission.new(params[:submission])
30 submission = Submission.new(params[:submission])
29 submission.user_id = session[:user_id]
31 submission.user_id = session[:user_id]
30 submission.language_id = 0
32 submission.language_id = 0
31 source = params['file'].read
33 source = params['file'].read
32 if source.length > 100_000
34 if source.length > 100_000
33 flash[:notice] = 'Error: file too long'
35 flash[:notice] = 'Error: file too long'
34 elsif (lang = Submission.find_language_in_source(source))==nil
36 elsif (lang = Submission.find_language_in_source(source))==nil
35 flash[:notice] = 'Error: cannot determine language used'
37 flash[:notice] = 'Error: cannot determine language used'
36 elsif ((submission.problem_id==-1) and
38 elsif ((submission.problem_id==-1) and
37 !(problem=Submission.find_problem_in_source(source)))
39 !(problem=Submission.find_problem_in_source(source)))
38 flash[:notice] = 'Error: cannot determine problem submitted'
40 flash[:notice] = 'Error: cannot determine problem submitted'
39 elsif ((submission.problem_id==-1) and
41 elsif ((submission.problem_id==-1) and
40 (problem.available == false))
42 (problem.available == false))
41 flash[:notice] = 'Error: problem is not available'
43 flash[:notice] = 'Error: problem is not available'
42 else
44 else
43 submission.problem_id = problem.id if submission.problem_id == -1
45 submission.problem_id = problem.id if submission.problem_id == -1
44 submission.source = source
46 submission.source = source
45 submission.language_id = lang.id
47 submission.language_id = lang.id
46 submission.submitted_at = Time.new
48 submission.submitted_at = Time.new
47 if submission.save == false
49 if submission.save == false
48 flash[:notice] = 'Error saving your submission'
50 flash[:notice] = 'Error saving your submission'
49 elsif Task.create(:submission_id => submission.id) == false
51 elsif Task.create(:submission_id => submission.id) == false
50 flash[:notice] = 'Error adding your submission to task queue'
52 flash[:notice] = 'Error adding your submission to task queue'
51 end
53 end
52 end
54 end
53 redirect_to :action => 'list'
55 redirect_to :action => 'list'
54 end
56 end
55
57
You need to be logged in to leave comments. Login now