Provides a single Comment model that can be attached to any model(s) within your app. It creates a Comment model and handles the plumbing between that model and any models that you declare to be commentable models.
Add the following line to your Gemfile
gem "acts_as_commentable", git: "https://github.com/BridgeU/acts_as_commentable" rails g comment
Then migrate your database to add the comments model:
rake db:migrate
Make the desired ActiveRecord model act as commentable:
class Post < ActiveRecord::Base
acts_as_commentable
endAdd a comment to a model instance by adding the following to the controller:
commentable = Post.create
comment = commentable.comments.create
comment.title = "First comment."
comment.comment = "This is the first comment."
comment.saveFetch comments for the commentable model by adding the following to the view:
commentable = Post.find(1)
comments = commentable.comments.recent.limit(10).allYou can also add different types of comments to a model:
class Todo < ActiveRecord::Base
acts_as_commentable :public, :private
endNote: This feature is only available from version 4.0 and above
To fetch the different types of comments for this model:
public_comments = Todo.find(1).public_comments
private_comments = Todo.find(1).private_commentsBy default, acts_as_commentable will assume you are using a Comment model.
To change this, or change any other join options, pass in an options hash:
class Todo < ActiveRecord::Base
acts_as_commentable class_name: 'MyComment'
endThis also works in conjunction with comment types:
class Todo < ActiveRecord::Base
acts_as_commentable :public, :private, { class_name: 'MyComment' }
endXelipe - This plugin is heavily influenced by Acts As Taggable.
Jack Dempsey, Chris Eppstein, Jim Ray, Matthew Van Horn, Ole Riesenberg, ZhangJinzhu, maddox, monocle, mrzor, Michael Bensoussan, JP Ferreira
http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/ http://www.juixe.com/projects/acts_as_commentable