comparison app/models/paste.rb @ 265:6cca1ab53337

Infinitely better error messages and notice.
author edogawaconan <me@myconan.net>
date Wed, 16 Oct 2013 02:56:30 +0900
parents a894d7696b7e
children 0bf1d6f75baa
comparison
equal deleted inserted replaced
264:fa4a1ba990ae 265:6cca1ab53337
4 before_validation :convert_newlines 4 before_validation :convert_newlines
5 before_validation :set_paste_hash 5 before_validation :set_paste_hash
6 before_validation :set_paste_key 6 before_validation :set_paste_key
7 before_validation :set_paste_secret 7 before_validation :set_paste_secret
8 validates :paste, :paste_hash, :key, :ip, :presence => true 8 validates :paste, :paste_hash, :key, :ip, :presence => true
9 validates :paste, :length => { :maximum => 1_000_000 } 9 validates :paste, :length => { :maximum => 1 }
10 10
11 def to_param 11 def to_param
12 path 12 path
13 end 13 end
14 14
17 return unless id.to_i.to_s == id 17 return unless id.to_i.to_s == id
18 begin 18 begin
19 self.where(secret: secret).find(id) 19 self.where(secret: secret).find(id)
20 rescue ActiveRecord::RecordNotFound 20 rescue ActiveRecord::RecordNotFound
21 nil 21 nil
22 end
23 end
24
25 def safe_destroy(param_key)
26 if key == param_key
27 destroy
28 else
29 errors.add(:key, "is invalid")
30 false
22 end 31 end
23 end 32 end
24 33
25 def path 34 def path
26 [id, secret.presence].compact.join("-") 35 [id, secret.presence].compact.join("-")