diff app/models/paste.rb @ 229:388504e43bcf

Properly return 404 when requesting invalid paste.
author Edho Arief <edho@myconan.net>
date Wed, 15 May 2013 14:10:35 +0900
parents d59731c3c7bf
children 1c750d3cde1b
line wrap: on
line diff
--- a/app/models/paste.rb	Mon May 13 13:20:53 2013 +0900
+++ b/app/models/paste.rb	Wed May 15 14:10:35 2013 +0900
@@ -15,7 +15,11 @@
   def self.safe_find(raw_id)
     id, secret = raw_id.split("-")
     return unless id.to_i.to_s == id
-    self.where(secret: secret).find(id)
+    begin
+      self.where(secret: secret).find(id)
+    rescue ActiveRecord::RecordNotFound
+      nil
+    end
   end
 
   def path