Class: Comment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comment
- Defined in:
- lib/generators/acts_as_commentable_upgrade_migration/comment.rb,
lib/generators/acts_as_commentable_with_threading_migration/templates/comment.rb
Class Method Summary collapse
-
.build_from(obj, user_id, comment) ⇒ Object
Helper class method that allows you to build a comment by passing a commentable object, a user_id, and comment text example in readme.
-
.find_commentable(commentable_str, commentable_id) ⇒ Object
Helper class method to look up a commentable object given the commentable class name and id.
Instance Method Summary collapse
-
#has_children? ⇒ Boolean
helper method to check if a comment has children.
Class Method Details
.build_from(obj, user_id, comment) ⇒ Object
Helper class method that allows you to build a comment by passing a commentable object, a user_id, and comment text example in readme
19 20 21 22 23 24 25 26 |
# File 'lib/generators/acts_as_commentable_upgrade_migration/comment.rb', line 19 def self.build_from(obj, user_id, comment) c = self.new c.commentable_id = obj.id c.commentable_type = obj.class.base_class.name c.body = comment c.user_id = user_id c end |
.find_commentable(commentable_str, commentable_id) ⇒ Object
Helper class method to look up a commentable object given the commentable class name and id
47 48 49 |
# File 'lib/generators/acts_as_commentable_upgrade_migration/comment.rb', line 47 def self.find_commentable(commentable_str, commentable_id) commentable_str.constantize.find(commentable_id) end |
Instance Method Details
#has_children? ⇒ Boolean
helper method to check if a comment has children
29 30 31 |
# File 'lib/generators/acts_as_commentable_upgrade_migration/comment.rb', line 29 def has_children? self.children.size > 0 end |