elight / acts_as_commentable_with_threading

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

This URL has Read+Write access

name age message
file CHANGELOG Loading commit data...
file MIT-LICENSE Sun Nov 16 09:01:14 -0800 2008 All specs pass already. Awesome. [elight]
file README
file Rakefile Sun Nov 16 09:01:14 -0800 2008 All specs pass already. Awesome. [elight]
file acts_as_commentable_with_threading.gemspec Sun Nov 16 12:15:08 -0800 2008 Gemspec fixes [elight]
file init.rb Sun Nov 16 09:01:14 -0800 2008 All specs pass already. Awesome. [elight]
file install.rb Sun Nov 16 09:01:14 -0800 2008 All specs pass already. Awesome. [elight]
directory lib/ Wed Mar 11 08:50:32 -0700 2009 fixed issue that prevents the use of the acts_a... [Casen]
directory spec/ Sun Nov 16 09:08:33 -0800 2008 renamed 'root_comments' to the more reasonable ... [elight]
README
Acts As Commentable (now with comment threads (TM)!!!  -- kidding on the (TM))
===================

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)

***NOTE: This plugin requires that you also install the awesome_nested_set plugin. 

    script/plugin install git://github.com/collectiveidea/awesome_nested_set.git

== Resources

Install

  Rails

   * To install as a plugin:
 
    script/plugin install git://github.com/elight/acts_as_commentable_with_threading.git 
 
 * Create a new rails migration and add the following self.up and self.down methods

 * These are the required fields for the database migration, however you may add any additional fields you need.
 
  def self.up
    create_table "comments", :force => true do |t|
      t.integer "commentable_id", :default => 0
      t.string "commentable_type", :limit => 15, :default => ""
      t.text "body", :default => ""
      t.integer "user_id", :default => 0, :null => false
      t.integer "parent_id"
      t.integer "lft"
      t.integer "rgt"
      t.timestamps
    end
  
    add_index "comments", "user_id"
    add_index "comments", "commentable_id"
  end

  def self.down
    drop_table :comments
  end

== Usage
 class Model < ActiveRecord::Base
   acts_as_commentable
 end
 
 * Add a comment to a model instance, for example an Article

  @article = Article.find(params[:id])
  @user_who_commented = @current_user
  @comment = Comment.build_from(@article, @user_who_commented.id, "Hey guys this is my comment!" )
  
 * 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 article, including child comments
  
  @all_comments = @article.comment_threads
  
 * To retrieve only the root comments without their children comments
  
  @root_comments = @article.root_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 comments children

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

  in lib/comment.rb uncomment the line "acts_as_voteable"
  in lib/acts_as_commentable_with_threading.rb uncomment the line "include Juixe::Acts::Voteable" near the top
  
  
 
 
 


== Credits

Jack Dempsey  - This plugin/gem is heavily influenced/liberally borrowed/stole from acts_as_commentable

which in turn credits....

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

== More

http://triple-dog-dare.com
http://evan.tiggerpalace.com