Description:
[web] fixed tasks viewing, changed routes for it
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@261 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r131:e25d802c4aec - - 2 files changed: 13 inserted, 5 deleted
@@ -1,34 +1,40 | |||
|
1 | 1 | class TasksController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :check_viewability |
|
4 | 4 | |
|
5 | 5 | def index |
|
6 | 6 | redirect_to :action => 'list' |
|
7 | 7 | end |
|
8 | 8 | |
|
9 | 9 | def list |
|
10 | 10 | @problems = Problem.find_available_problems |
|
11 | 11 | @user = User.find(session[:user_id]) |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | def view |
|
15 | - file_name = "#{RAILS_ROOT}/data/tasks/#{params[:file]}" | |
|
16 | - if !FileTest.exists?(file_name) | |
|
15 | + base_filename = File.basename("#{params[:file]}.#{params[:ext]}") | |
|
16 | + filename = "#{RAILS_ROOT}/data/tasks/#{base_filename}" | |
|
17 | + if !FileTest.exists?(filename) | |
|
17 | 18 | redirect_to :action => 'index' and return |
|
18 | 19 | end |
|
19 | - # ask Apache to send the file | |
|
20 | - response.headers['X-Sendfile'] = file_name | |
|
21 | - render :nothing => true | |
|
20 | + # ask Apache to send the file --- doesn't quite work... | |
|
21 | + #response.headers['Content-Type'] = "application/force-download" | |
|
22 | + #response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\"" | |
|
23 | + #response.headers['Content-length'] = File.size(filename) | |
|
24 | + #response.headers['X-Sendfile'] = filename | |
|
25 | + #render :nothing => true | |
|
26 | + | |
|
27 | + send_file filename, :stream => false, :filename => base_filename | |
|
22 | 28 | end |
|
23 | 29 | |
|
24 | 30 | protected |
|
25 | 31 | |
|
26 | 32 | def check_viewability |
|
27 | 33 | user = User.find(session[:user_id]) |
|
28 | 34 | if user==nil or !Configuration.show_tasks_to?(user) |
|
29 | 35 | redirect_to :controller => 'main', :action => 'list' |
|
30 | 36 | return false |
|
31 | 37 | end |
|
32 | 38 | end |
|
33 | 39 | |
|
34 | 40 | end |
@@ -1,26 +1,28 | |||
|
1 | 1 | ActionController::Routing::Routes.draw do |map| |
|
2 | 2 | map.resources :announcements |
|
3 | 3 | map.resources :sites |
|
4 | 4 | |
|
5 | 5 | # The priority is based upon order of creation: first created -> highest priority. |
|
6 | 6 | |
|
7 | 7 | # Sample of regular route: |
|
8 | 8 | # map.connect 'products/:id', :controller => 'catalog', :action => 'view' |
|
9 | 9 | # Keep in mind you can assign values other than :controller and :action |
|
10 | 10 | |
|
11 | 11 | # Sample of named route: |
|
12 | 12 | # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' |
|
13 | 13 | # This route can be invoked with purchase_url(:id => product.id) |
|
14 | 14 | |
|
15 | 15 | # You can have the root of your site routed by hooking up '' |
|
16 | 16 | # -- just remember to delete public/index.html. |
|
17 | 17 | map.connect '', :controller => 'main', :action => 'login' |
|
18 | 18 | |
|
19 | 19 | # Allow downloading Web Service WSDL as a file with an extension |
|
20 | 20 | # instead of a file named 'wsdl' |
|
21 | 21 | map.connect ':controller/service.wsdl', :action => 'wsdl' |
|
22 | 22 | |
|
23 | + map.connect 'tasks/view/:file.:ext', :controller => 'tasks', :action => 'view' | |
|
24 | + | |
|
23 | 25 | # Install the default route as the lowest priority. |
|
24 | 26 | map.connect ':controller/:action/:id.:format' |
|
25 | 27 | map.connect ':controller/:action/:id' |
|
26 | 28 | end |
You need to be logged in to leave comments.
Login now