2008-01-18 02:31:37 -05:00
|
|
|
require 'models/topic'
|
2005-11-04 00:46:28 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
class Reply < Topic
|
2008-04-30 01:25:52 -04:00
|
|
|
named_scope :base
|
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
|
2006-03-18 15:25:50 -05:00
|
|
|
has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id"
|
2004-12-09 07:50:18 -05:00
|
|
|
|
|
|
|
validate :errors_on_empty_content
|
|
|
|
validate_on_create :title_is_wrong_create
|
2008-01-18 02:27:03 -05:00
|
|
|
|
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
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2004-12-09 07:50:18 -05:00
|
|
|
def errors_on_empty_content
|
2004-11-23 20:04:44 -05:00
|
|
|
errors.add("content", "Empty") unless attribute_present? "content"
|
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2004-11-23 20:04:44 -05:00
|
|
|
def validate_on_create
|
|
|
|
if attribute_present?("title") && attribute_present?("content") && content == "Mismatch"
|
2008-01-18 02:27:03 -05:00
|
|
|
errors.add("title", "is Content Mismatch")
|
2004-11-23 20:04:44 -05:00
|
|
|
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
|
2006-03-09 12:23:57 -05:00
|
|
|
belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
|
2005-11-04 00:46:28 -05:00
|
|
|
end
|
2008-12-31 04:43:13 -05:00
|
|
|
|
|
|
|
module Web
|
|
|
|
class Reply < Web::Topic
|
|
|
|
belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true, :class_name => 'Web::Topic'
|
|
|
|
end
|
|
|
|
end
|