Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 6, 2019. It is now read-only.

codequest-eu/acts_as_commentable_with_threading

 
 

Repository files navigation

Acts As Commentable with Threading

Allows for threaded comments to be added to multiple and different models. Drop-in compatible for acts_as_commentable (however requiring a database schema change)

Requirements

This gem is for Rails 3 and later versions only.

This gem depends on CollectiveIdea's Awesome Nested Set gem. It is installed if not already present when you install this gem.

You can find the gem on GitHub at collectiveidea/awesome_nested_set

Install

In your Gemfile, add:

gem 'acts_as_commentable_with_threading', git: '[email protected]:codequest-eu/acts_as_commentable_with_threading.git'

and run bundle install.

Migrations

  • To install from scratch:

    rails generate acts_as_commentable_with_threading_migration

This will generate the migration script necessary for the table

Usage

class Car < ActiveRecord::Base
  acts_as_commentable :engine, :design
end
  • Add a comment to a model instance, for example an Car:

      @car = Car.find(params[:id])
      @comment = @car.engine_comment_threads.build(:body => "Hey guys this is my comment!")
      @comment.user = current_user
      @comment.save
    
  • To make a newly created comment into a child/reply of another comment:

      @comment.move_to_child_of(the_desired_parent_comment)
    
  • To retrieve all comments for an car, including child comments:

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

      @root_engine_comments = @car.root_engine_comments
    
  • To check if a comment has children:

      @comment.has_children?
    
  • To verify the number of children a comment has:

      @comment.children.size
    
  • To retrieve a comment's children:

      @comment.children
    
  • If you plan to use the acts_as_votable plugin with your comment system be sure to uncomment two things:

Credits

And in turn...

  • Xelipe - Because acts_as_commentable was heavily influenced by Acts As Taggable.

More

About

Similar to acts_as_commentable; however, utilizes awesome_nested_set to provide threaded comments

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%