# HG changeset patch # User jittat # Date 2008-05-09 14:53:37 # Node ID e25d802c4aec83eb6940084cf92c21ecc89d0ba6 # Parent f343b8fb7d21430d37716a3140bd873e3d00a225 [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 diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -12,13 +12,19 @@ end def view - file_name = "#{RAILS_ROOT}/data/tasks/#{params[:file]}" - if !FileTest.exists?(file_name) + base_filename = File.basename("#{params[:file]}.#{params[:ext]}") + filename = "#{RAILS_ROOT}/data/tasks/#{base_filename}" + if !FileTest.exists?(filename) redirect_to :action => 'index' and return end - # ask Apache to send the file - response.headers['X-Sendfile'] = file_name - render :nothing => true + # ask Apache to send the file --- doesn't quite work... + #response.headers['Content-Type'] = "application/force-download" + #response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\"" + #response.headers['Content-length'] = File.size(filename) + #response.headers['X-Sendfile'] = filename + #render :nothing => true + + send_file filename, :stream => false, :filename => base_filename end protected diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,8 @@ # instead of a file named 'wsdl' map.connect ':controller/service.wsdl', :action => 'wsdl' + map.connect 'tasks/view/:file.:ext', :controller => 'tasks', :action => 'view' + # Install the default route as the lowest priority. map.connect ':controller/:action/:id.:format' map.connect ':controller/:action/:id'