comparison 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
comparison
equal deleted inserted replaced
424:967233b26404 425:9369ad2f2ce8
13 def to_param 13 def to_param
14 path 14 path
15 end 15 end
16 16
17 def self.safe_find(raw_id) 17 def self.safe_find(raw_id)
18 id, secret = raw_id.to_s.split("-") 18 /\A(?<id>[0-9]+)(?:-(?<secret>[0-9a-f]+))?\z/ =~ raw_id.to_s
19 return unless id.to_i.to_s == id 19
20 begin 20 where(:secret => secret, :id => id)
21 where(:secret => secret).find(id)
22 rescue ActiveRecord::RecordNotFound
23 nil
24 end
25 end 21 end
26 22
27 def self.graceful_create(params) 23 def self.graceful_create(params)
28 paste = new(params) 24 paste = new(params)
29 fresh = true 25 fresh = true