]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/site_controller.rb
Merge remote-tracking branch 'upstream/pull/2444'
[rails.git] / app / controllers / site_controller.rb
index f57bb7c256cb3c27af0f9716da3df8aaf86b484c..1fc916e7f8436c3f3a22d6742c5ffc1395ee3932 100644 (file)
@@ -77,26 +77,30 @@ class SiteController < ApplicationController
       )
     end
 
-    if params[:node]
-      bbox = Node.find(params[:node]).bbox.to_unscaled
-      @lat = bbox.centre_lat
-      @lon = bbox.centre_lon
-      @zoom = 18
-    elsif params[:way]
-      bbox = Way.find(params[:way]).bbox.to_unscaled
-      @lat = bbox.centre_lat
-      @lon = bbox.centre_lon
-      @zoom = 17
-    elsif params[:note]
-      note = Note.find(params[:note])
-      @lat = note.lat
-      @lon = note.lon
-      @zoom = 17
-    elsif params[:gpx] && current_user
-      trace = Trace.visible_to(current_user).find(params[:gpx])
-      @lat = trace.latitude
-      @lon = trace.longitude
-      @zoom = 16
+    begin
+      if params[:node]
+        bbox = Node.visible.find(params[:node]).bbox.to_unscaled
+        @lat = bbox.centre_lat
+        @lon = bbox.centre_lon
+        @zoom = 18
+      elsif params[:way]
+        bbox = Way.visible.find(params[:way]).bbox.to_unscaled
+        @lat = bbox.centre_lat
+        @lon = bbox.centre_lon
+        @zoom = 17
+      elsif params[:note]
+        note = Note.visible.find(params[:note])
+        @lat = note.lat
+        @lon = note.lon
+        @zoom = 17
+      elsif params[:gpx] && current_user
+        trace = Trace.visible_to(current_user).find(params[:gpx])
+        @lat = trace.latitude
+        @lon = trace.longitude
+        @zoom = 16
+      end
+    rescue ActiveRecord::RecordNotFound
+      # don't try and derive a location from a missing/deleted object
     end
   end