]> git.openstreetmap.org Git - rails.git/blob - app/models/diary_comment.rb
Supply hints for OSRM
[rails.git] / app / models / diary_comment.rb
1 class DiaryComment < ActiveRecord::Base
2   belongs_to :user
3   belongs_to :diary_entry
4
5   validates_presence_of :body
6   validates_associated :diary_entry
7
8   after_initialize :set_defaults
9   after_save :spam_check
10
11   def body
12     RichText.new(read_attribute(:body_format), read_attribute(:body))
13   end
14
15   def digest
16     md5 = Digest::MD5.new
17     md5 << diary_entry_id.to_s
18     md5 << user_id.to_s
19     md5 << created_at.xmlschema
20     md5 << body
21     md5.hexdigest
22   end
23
24 private
25
26   def set_defaults
27     self.body_format = "markdown" unless self.attribute_present?(:body_format)
28   end
29
30   def spam_check
31     user.spam_check
32   end
33 end