No commit activity in last 3 years
No release in over 3 years
Create comments along with their threads on any commentable object. Use Ancestry gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.4

Runtime

~> 2.1
~> 4.0
 Project Readme

Threadable Comments

Allows for threaded comments to be added to different models while comment hierarchy is handled via the ancestry gem (uses a materialised path pattern).

Install

In your Gemfile, add:

gem 'threadable_comments'

and run bundle install.

Migrations

  • To install:

      rails generate threadable_comments:migration
    

    This will generate the migration script necessary for the table

Usage

class Article < ActiveRecord::Base
  has_threadable_comments
end
  • Add a comment to a model instance, for example an Article:

      @user_who_commented = @current_user
      @article.add_comment "This is my comment!", @user_who_commented
    
  • To reply to a comment:

      @comment.reply = "This is a reply!", @user_who_commented
    
  • To retrieve all comments for an article, including child comments:

      @all_comments = @article.comments
    
  • To retrieve only the root comments without their child comments:

      @root_comments = @article.root_comments
    
  • To check if a comment has children:

      @comment.has_children?
    
  • To get a comment's parent:

      @comment.parent
    
  • To verify the number of direct children a comment has:

      @comment.children.count
    
  • To verify the number of children and grand-children a comment has:

      @comment.descendants.count
    
  • To retrieve a comment's children:

      @comment.children
    

Tips

Once you have a comment in your hands, you can use all the methods and scope of the ancestry gem to access children and parents of the comment.

Credits