Mercurial > zeropaste
comparison 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 |
comparison
equal
deleted
inserted
replaced
228:4a79bc78e90e | 229:388504e43bcf |
---|---|
13 end | 13 end |
14 | 14 |
15 def self.safe_find(raw_id) | 15 def self.safe_find(raw_id) |
16 id, secret = raw_id.split("-") | 16 id, secret = raw_id.split("-") |
17 return unless id.to_i.to_s == id | 17 return unless id.to_i.to_s == id |
18 self.where(secret: secret).find(id) | 18 begin |
19 self.where(secret: secret).find(id) | |
20 rescue ActiveRecord::RecordNotFound | |
21 nil | |
22 end | |
19 end | 23 end |
20 | 24 |
21 def path | 25 def path |
22 [id, secret.presence].compact.join("-") | 26 [id, secret.presence].compact.join("-") |
23 end | 27 end |