6 belongs_to
:topic, :foreign_key => "parent_id", :counter_cache => true
7 has_many
:replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
9 validate
:errors_on_empty_content
10 validate_on_create
:title_is_wrong_create
12 attr_accessible
:title, :author_name, :author_email_address, :written_on, :content, :last_read
15 errors
.add("title", "Empty") unless attribute_present
? "title"
18 def errors_on_empty_content
19 errors
.add("content", "Empty") unless attribute_present
? "content"
22 def validate_on_create
23 if attribute_present
?("title") && attribute_present
?("content") && content
== "Mismatch"
24 errors
.add("title", "is Content Mismatch")
28 def title_is_wrong_create
29 errors
.add("title", "is Wrong Create") if attribute_present
?("title") && title
== "Wrong Create"
32 def validate_on_update
33 errors
.add("title", "is Wrong Update") if attribute_present
?("title") && title
== "Wrong Update"
37 class SillyReply
< Reply
38 belongs_to
:reply, :foreign_key => "parent_id", :counter_cache => :replies_count