Module: ActsAsAble::Commenter::InstanceMethods
- Defined in:
- lib/acts_as_able/commenter.rb
Instance Method Summary collapse
-
#comment(content, obj, parent_comment = nil) ⇒ Object
评论某对象.
-
#comment?(obj) ⇒ Boolean
是否评论了某对象 & 回复了某对象的评论.
-
#commentings(commentable_type) ⇒ Object
查看某种类型评论的所有对象.
Instance Method Details
#comment(content, obj, parent_comment = nil) ⇒ Object
评论某对象
19 20 21 22 23 24 25 |
# File 'lib/acts_as_able/commenter.rb', line 19 def comment(content, obj, parent_comment = nil) if parent_comment.present? && parent_comment.is_a?(Comment) self.comments.create(content: content,commentable_type: class_name(obj), commentable_id: obj.id, parent_id: parent_comment.id ) else self.comments.create(content: content, commentable_type: class_name(obj), commentable_id: obj.id,) end end |
#comment?(obj) ⇒ Boolean
是否评论了某对象 & 回复了某对象的评论
28 29 30 |
# File 'lib/acts_as_able/commenter.rb', line 28 def comment?(obj) !comment_by(obj).blank? end |
#commentings(commentable_type) ⇒ Object
查看某种类型评论的所有对象
33 34 35 |
# File 'lib/acts_as_able/commenter.rb', line 33 def commentings(commentable_type) return commentable_type.constantize.where(id: self.comments.where(commentable_type: commentable_type).pluck(:commentable_id)) end |