Rails gem for building a commenting systems by using Active Records.
by Peter Wong <peter@peterwongpp.com>
GitHub Project: github.com/peterwongpp/commentem
TODO List:
Better documentation (Making use of rdoc and ri)
Write tests
If you would like to install it as gem, put this in your Gemfile:
gem'commentem'
If you would rather like to install it as plugin, run this command in your console:
rails plugin install git://github.com/peterwongpp/commentem.git
And then run:
railsgeneratecommentemrakedb:migrate
Just add acts_as_commenter and acts_as_commentable to your models. You could mix them in the same model if you like. See the example below:
# A user can comment on users or postsclassUser<ActiveRecord::Baseacts_as_commenteracts_as_commentableendclassPost<ActiveRecord::Baseacts_as_commentableend# To comment@user = User.find(1) @user2 = User.find(2) @post = Post.find(1) @user.comment(@user2, "comment goes to here") @user.comment(@post, "comment goes to here")
@usr.comment(@user, “you could comment on yourself too”)
# To read comments:@user = User.find(1) @user2 = User.find(2) @post = Post.find(1) @user2.comments@post.comments@user.comments# retrieve all comments from @user, including on @user2 and @post@user.comments_on(@user2) # same as @user2.comments@user.comments_on(@post) # same as @post.comments
Version 1.0.3
Fixed the silly typo error on the generated Comment model.
Version 1.0.2
Updated the code of the comment model to use class methods instead of scopes (don’t worry, no any change to the usage).
Version 1.0.1
Updated the Readme file.
Version 1.0.0
The Commentem gem is published with basic necessary functionalities (commenting and querying).