comparison app/models/paste.rb @ 71:7bb46d9febad

Ensure we're gsubbing a string.
author Edho Arief <edho@myconan.net>
date Thu, 04 Oct 2012 10:38:55 +0700
parents 8f0fb869e770
children a9dba6a3008b
comparison
equal deleted inserted replaced
70:8f0fb869e770 71:7bb46d9febad
9 def set_paste_hash 9 def set_paste_hash
10 self.paste_hash = Digest::SHA512.hexdigest("#{paste}\n") 10 self.paste_hash = Digest::SHA512.hexdigest("#{paste}\n")
11 end 11 end
12 12
13 def convert_newlines 13 def convert_newlines
14 self.paste = self.paste.gsub("\r\n", "\n").gsub("\r", "\n") 14 self.paste = self.paste.to_s.gsub("\r\n", "\n").gsub("\r", "\n")
15 end 15 end
16 16
17 def paste_limit 17 def paste_limit
18 ip_post_recent_count = self.class.where(:ip => self.ip).where('created_at > ?', Time.now - 1.hour).count 18 ip_post_recent_count = self.class.where(:ip => self.ip).where('created_at > ?', Time.now - 1.hour).count
19 errors.add :base, :limit if ip_post_recent_count > 100 19 errors.add :base, :limit if ip_post_recent_count > 100