Show More
Commit Description:
update NOTES...
Commit Description:
update NOTES git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@120 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
app/controllers/test_controller.rb | 52 lines | 1.3 KiB | text/x-ruby | RubyLexer |
class TestController < ApplicationController
before_filter :authenticate
verify :method => :post, :only => [:test_submit],
:redirect_to => { :action => :index }
def index
@user = User.find(session[:user_id])
prepare_index_information
end
def submit
@user = User.find(session[:user_id])
test_request = TestRequest.new_from_form_params(@user,params[:test_request])
if test_request.save
redirect_to :action => 'index'
else
flash[:notice] = 'Error saving your test submission'
redirect_to :action => 'index'
end
end
def read
user = User.find(session[:user_id])
test_request = TestRequest.find(params[:id])
if test_request.user_id != user.id
flash[:notice] = 'Invalid output'
redirect_to :action => 'index'
return
end
if test_request.output_file_name!=nil
data = File.open(test_request.output_file_name).read(2048)
if data==nil
data=""
end
send_data(data,
{:filename => 'output.txt',
:type => 'text/plain'})
return
end
redirect_to :action => 'index'
end
protected
def prepare_index_information
@submissions = Submission.find_last_for_all_available_problems(@user.id)
@problems = @submissions.collect { |submission| submission.problem }
end
end