acts_as_commentable

The ActiveRecord acts_as_commentable plugin

  • 所有者: jackdempsey/acts_as_commentable
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

= Acts As Commentable

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.

== Installation :

Add the following line to your Gemfile

=== Rails 4

gem 'acts_as_commentable'

=== Rails 3

gem 'acts_as_commentable', '3.0.1'

=== Rails 2

gem 'acts_as_commentable', git: 'git@github.com:jackdempsey/acts_as_commentable.git', branch: '2.x'

== Generator

=== Rails 3+

rails g comment

=== Rails 2

script/generate comment

Then migrate your database to add the comments model:

rake db:migrate

== Usage

Make the desired ActiveRecord model act as commentable:

class Post < ActiveRecord::Base
acts_as_commentable
end

Add 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.save

Fetch comments for the commentable model by adding the following to the view:

commentable = Post.find(1)
comments = commentable.comments.recent.limit(10).all

You can also add different types of comments to a model:

class Todo < ActiveRecord::Base
acts_as_commentable :public, :private
end

Note: 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_comments

By 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'
end

This also works in conjunction with comment types:

class Todo < ActiveRecord::Base
  acts_as_commentable :public, :private, { class_name: 'MyComment' }
end

== Credits

Xelipe - This plugin is heavily influenced by Acts As Taggable.

== Contributors

Jack Dempsey, Chris Eppstein, Jim Ray, Matthew Van Horn, Ole Riesenberg, ZhangJinzhu, maddox, monocle, mrzor, Michael Bensoussan

== More

http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
http://www.juixe.com/projects/acts_as_commentable

主要指标

概览
名称与所有者jackdempsey/acts_as_commentable
主编程语言Ruby
编程语言Ruby (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2008-03-12 07:11:22
推送于2023-01-12 10:51:16
最后一次提交2015-01-30 21:07:21
发布数1
最新版本名称v2.0.1 (发布于 )
第一版名称v2.0.1 (发布于 )
用户参与
星数834
关注者数12
派生数184
提交数110
已启用问题?
问题数35
打开的问题数10
拉请求数23
打开的拉请求数14
关闭的拉请求数6
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?