]> git.openstreetmap.org Git - rails.git/blob - app/models/diary_comment.rb
Remove geolink class from add note button while adding notes
[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   attr_accessible :body
9
10   after_initialize :set_defaults
11   after_save :spam_check
12
13   def body
14     RichText.new(read_attribute(:body_format), read_attribute(:body))
15   end
16
17   def digest
18     md5 = Digest::MD5.new
19     md5 << diary_entry_id.to_s
20     md5 << user_id.to_s
21     md5 << created_at.xmlschema
22     md5 << body
23     md5.hexdigest
24   end
25
26 private
27
28   def set_defaults
29     self.body_format = "markdown" unless self.attribute_present?(:body_format)
30   end
31
32   def spam_check
33     user.spam_check
34   end
35 end