diff app/models/paste.rb @ 425:9369ad2f2ce8

Simplify logic
author nanaya <me@myconan.net>
date Mon, 26 Oct 2015 14:09:13 +0900
parents 2ad092e60975
children 9fc6b919369c
line wrap: on
line diff
--- a/app/models/paste.rb	Sat Sep 26 03:56:24 2015 +0900
+++ b/app/models/paste.rb	Mon Oct 26 14:09:13 2015 +0900
@@ -15,13 +15,9 @@
   end
 
   def self.safe_find(raw_id)
-    id, secret = raw_id.to_s.split("-")
-    return unless id.to_i.to_s == id
-    begin
-      where(:secret => secret).find(id)
-    rescue ActiveRecord::RecordNotFound
-      nil
-    end
+    /\A(?<id>[0-9]+)(?:-(?<secret>[0-9a-f]+))?\z/ =~ raw_id.to_s
+
+    where(:secret => secret, :id => id)
   end
 
   def self.graceful_create(params)