]> git.openstreetmap.org Git - rails.git/blob - app/models/diary_comment.rb
Include useful URLs in note responses
[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
12   def body
13     RichText.new(read_attribute(:body_format), read_attribute(:body))
14   end
15
16   def digest
17     md5 = Digest::MD5.new
18     md5 << diary_entry_id.to_s
19     md5 << user_id.to_s
20     md5 << created_at.xmlschema
21     md5 << body
22     md5.hexdigest
23   end
24
25 private
26
27   def set_defaults
28     self.body_format = "markdown" unless self.attribute_present?(:body_format)
29   end
30 end