Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

threadable_comments

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

threadable_comments

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 06 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc