]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/trace_controller.rb
Handle errors a bit better.
[rails.git] / app / controllers / trace_controller.rb
index 2001fdb2f619a6ac38c45ab75a78e20915ef78f9..d8405987442b251ffd98f84e637aaaea617d5d39 100644 (file)
@@ -108,11 +108,14 @@ class TraceController < ApplicationController
 
   def data
     trace = Trace.find(params[:id])
-    if trace and (trace.public? or (@user and @user == trace.user))
+
+    if trace.public? or (@user and @user == trace.user)
       send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment')
     else
       render :nothing, :status => :not_found
     end
+  rescue ActiveRecord::RecordNotFound
+    render :nothing => true, :status => :not_found
   end
 
   def make_public
@@ -153,10 +156,14 @@ class TraceController < ApplicationController
   def picture
     trace = Trace.find(params[:id])
 
-    if trace.public? or (@user and @user == trace.user)
-      send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline')
+    if trace.inserted?
+      if trace.public? or (@user and @user == trace.user)
+        send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline')
+      else
+        render :nothing, :status => :forbidden
+      end
     else
-      render :nothing, :status => :forbidden
+      render :nothing => true, :status => :not_found
     end
   rescue ActiveRecord::RecordNotFound
     render :nothing => true, :status => :not_found
@@ -165,10 +172,14 @@ class TraceController < ApplicationController
   def icon
     trace = Trace.find(params[:id])
 
-    if trace.public? or (@user and @user == trace.user)
-      send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline')
+    if trace.inserted?
+      if trace.public? or (@user and @user == trace.user)
+        send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline')
+      else
+        render :nothing, :status => :forbidden
+      end
     else
-      render :nothing, :status => :forbidden
+      render :nothing => true, :status => :not_found
     end
   rescue ActiveRecord::RecordNotFound
     render :nothing => true, :status => :not_found
@@ -203,7 +214,7 @@ class TraceController < ApplicationController
       name = params[:file].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane
 
       do_create(name, params[:tags], params[:description], params[:public]) do |f|
-        f.write(request[:file].read)
+        f.write(params[:file].read)
       end
 
       if @trace.id