11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/comment/commentable_methods.rb', line 11
def
has_many :comments, {:as => :commentable, :dependent => :destroy}
class_eval %{
def self.find_comments_for(obj)
Comment.find_comments_for_commentable(self.base_class.name, obj.id)
end
def self.find_comments_by_user(user)
commentable = self.base_class.name
Comment.where(["user_id = ? and commentable_type = ?", user.id, commentable]).order("created_at DESC")
end
def comments_ordered_by_submitted
Comment.find_comments_for_commentable(self.class.name, id)
end
def add_comments(comment)
comments << comment
end
}
end
|