2004-11-23 20:04:44 -05:00
|
|
|
class Reply < Topic
|
|
|
|
belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
|
2004-12-12 13:12:57 -05:00
|
|
|
has_many :silly_replies, :dependent => true, :foreign_key => "parent_id"
|
2004-12-09 07:50:18 -05:00
|
|
|
|
|
|
|
validate :errors_on_empty_content
|
|
|
|
validate_on_create :title_is_wrong_create
|
2004-11-23 20:04:44 -05:00
|
|
|
|
|
|
|
attr_accessible :title, :author_name, :author_email_address, :written_on, :content, :last_read
|
|
|
|
|
|
|
|
def validate
|
|
|
|
errors.add("title", "Empty") unless attribute_present? "title"
|
2004-12-09 07:50:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def errors_on_empty_content
|
2004-11-23 20:04:44 -05:00
|
|
|
errors.add("content", "Empty") unless attribute_present? "content"
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_on_create
|
|
|
|
if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
|
|
|
|
errors.add("title", "is Content Mismatch")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-12-09 07:50:18 -05:00
|
|
|
def title_is_wrong_create
|
|
|
|
errors.add("title", "is Wrong Create") if attribute_present?("title") && title == "Wrong Create"
|
|
|
|
end
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def validate_on_update
|
|
|
|
errors.add("title", "is Wrong Update") if attribute_present?("title") && title == "Wrong Update"
|
|
|
|
end
|
2004-12-12 13:12:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class SillyReply < Reply
|
2004-11-23 20:04:44 -05:00
|
|
|
end
|