acts_as_commentable 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +59 -0
- data/lib/comment_methods.rb +3 -2
- data/lib/commentable_methods.rb +4 -4
- data/lib/generators/comment/templates/create_comments.rb +1 -1
- metadata +8 -6
- data/README +0 -73
data/README.rdoc
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Acts As Commentable
|
2
|
+
=================
|
3
|
+
|
4
|
+
Allows for comments to be added to multiple and different models.
|
5
|
+
|
6
|
+
== Resources
|
7
|
+
|
8
|
+
Install
|
9
|
+
|
10
|
+
* To install as a gem (recommended):
|
11
|
+
** gem install acts_as_commentable
|
12
|
+
** add the following line to your environment.rb: config.gem 'acts_as_commentable'
|
13
|
+
** If using bundler then just add "gem 'acts_as_commentable'" to your Gemfile and "bundle install"
|
14
|
+
|
15
|
+
|
16
|
+
* To install as a plugin
|
17
|
+
** Rails 3: script/plugin install http://github.com/jackdempsey/acts_as_commentable.git
|
18
|
+
** Rails 2: script/plugin install http://github.com/jackdempsey/acts_as_commentable.git -r 2.x
|
19
|
+
|
20
|
+
|
21
|
+
Generate your comment model:
|
22
|
+
|
23
|
+
script/generate comment
|
24
|
+
|
25
|
+
Then migrate your database:
|
26
|
+
|
27
|
+
rake db:migrate
|
28
|
+
|
29
|
+
== Usage
|
30
|
+
|
31
|
+
* Make your ActiveRecord model act as commentable.
|
32
|
+
|
33
|
+
class Post < ActiveRecord::Base
|
34
|
+
acts_as_commentable
|
35
|
+
end
|
36
|
+
|
37
|
+
* Add a comment to a model instance
|
38
|
+
|
39
|
+
commentable = Post.create
|
40
|
+
commentable.comments.create(:title => "First comment.", :comment => "This is the first comment.")
|
41
|
+
|
42
|
+
* Fetch comments for a commentable model:
|
43
|
+
|
44
|
+
commentable = Post.find(1)
|
45
|
+
comments = commentable.comments.recent.limit(10).all
|
46
|
+
|
47
|
+
|
48
|
+
== Credits
|
49
|
+
|
50
|
+
Xelipe - This plugin is heavily influenced by Acts As Taggable.
|
51
|
+
|
52
|
+
== Contributors
|
53
|
+
|
54
|
+
Jack Dempsey, Chris Eppstein, Jim Ray, Matthew Van Horn, Ole Riesenberg, ZhangJinzhu, maddox, monocle
|
55
|
+
|
56
|
+
== More
|
57
|
+
|
58
|
+
http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
|
59
|
+
http://www.juixe.com/projects/acts_as_commentable
|
data/lib/comment_methods.rb
CHANGED
@@ -29,8 +29,9 @@ module ActsAsCommentable
|
|
29
29
|
# Helper class method to look up a commentable object
|
30
30
|
# given the commentable class name and id
|
31
31
|
def find_commentable(commentable_str, commentable_id)
|
32
|
-
commentable_str.constantize
|
33
|
-
|
32
|
+
model = commentable_str.constantize
|
33
|
+
model.respond_to?(:find_comments_for) ? model.find(commentable_id) : nil
|
34
|
+
end
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
data/lib/commentable_methods.rb
CHANGED
@@ -10,8 +10,8 @@ module Juixe
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module ClassMethods
|
13
|
-
def acts_as_commentable
|
14
|
-
has_many :comments, :as => :commentable, :dependent => :destroy
|
13
|
+
def acts_as_commentable(options={})
|
14
|
+
has_many :comments, {:as => :commentable, :dependent => :destroy}.merge(options)
|
15
15
|
include Juixe::Acts::Commentable::InstanceMethods
|
16
16
|
extend Juixe::Acts::Commentable::SingletonMethods
|
17
17
|
end
|
@@ -22,7 +22,7 @@ module Juixe
|
|
22
22
|
# Helper method to lookup for comments for a given object.
|
23
23
|
# This method is equivalent to obj.comments.
|
24
24
|
def find_comments_for(obj)
|
25
|
-
commentable =
|
25
|
+
commentable = self.base_class.name
|
26
26
|
Comment.find_comments_for_commentable(commentable, obj.id)
|
27
27
|
end
|
28
28
|
|
@@ -30,7 +30,7 @@ module Juixe
|
|
30
30
|
# the mixin commentable type written by a given user.
|
31
31
|
# This method is NOT equivalent to Comment.find_comments_for_user
|
32
32
|
def find_comments_by_user(user)
|
33
|
-
commentable =
|
33
|
+
commentable = self.base_class.name
|
34
34
|
Comment.where(["user_id = ? and commentable_type = ?", user.id, commentable]).order("created_at DESC")
|
35
35
|
end
|
36
36
|
end
|
@@ -2,7 +2,7 @@ class CreateComments < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table :comments do |t|
|
4
4
|
t.string :title, :limit => 50, :default => ""
|
5
|
-
t.text :comment
|
5
|
+
t.text :comment
|
6
6
|
t.references :commentable, :polymorphic => true
|
7
7
|
t.references :user
|
8
8
|
t.timestamps
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 3
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 3.0.
|
8
|
+
- 1
|
9
|
+
version: 3.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Cosmin Radoi, Jack Dempsey, Xelipe, Chris Eppstein
|
@@ -14,7 +14,7 @@ autorequire: acts_as_commentable
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-28 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -25,11 +25,11 @@ executables: []
|
|
25
25
|
extensions: []
|
26
26
|
|
27
27
|
extra_rdoc_files:
|
28
|
-
- README
|
28
|
+
- README.rdoc
|
29
29
|
- MIT-LICENSE
|
30
30
|
files:
|
31
31
|
- MIT-LICENSE
|
32
|
-
- README
|
32
|
+
- README.rdoc
|
33
33
|
- lib/acts_as_commentable.rb
|
34
34
|
- lib/comment_methods.rb
|
35
35
|
- lib/commentable_methods.rb
|
@@ -50,6 +50,7 @@ rdoc_options: []
|
|
50
50
|
require_paths:
|
51
51
|
- lib
|
52
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
53
54
|
requirements:
|
54
55
|
- - ">="
|
55
56
|
- !ruby/object:Gem::Version
|
@@ -57,6 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
58
|
- 0
|
58
59
|
version: "0"
|
59
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
60
62
|
requirements:
|
61
63
|
- - ">="
|
62
64
|
- !ruby/object:Gem::Version
|
@@ -66,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
68
|
requirements: []
|
67
69
|
|
68
70
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.3.
|
71
|
+
rubygems_version: 1.3.7
|
70
72
|
signing_key:
|
71
73
|
specification_version: 3
|
72
74
|
summary: Plugin/gem that provides comment functionality
|
data/README
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
Acts As Commentable
|
2
|
-
=================
|
3
|
-
|
4
|
-
Allows for comments to be added to multiple and different models.
|
5
|
-
|
6
|
-
== Resources
|
7
|
-
|
8
|
-
Install
|
9
|
-
|
10
|
-
Rails
|
11
|
-
|
12
|
-
* To install as a plugin:
|
13
|
-
|
14
|
-
script/plugin install http://github.com/jackdempsey/acts_as_commentable.git
|
15
|
-
|
16
|
-
* To install as a gem
|
17
|
-
sudo gem install
|
18
|
-
|
19
|
-
Merb/Rails
|
20
|
-
|
21
|
-
* To install as a gem:
|
22
|
-
Run the following if you haven't already:
|
23
|
-
gem sources -a http://gems.github.com
|
24
|
-
|
25
|
-
Install the gem(s):
|
26
|
-
sudo gem install jackdempsey-acts_as_commentable
|
27
|
-
|
28
|
-
add the folloowing line to your environment.rb
|
29
|
-
config.gem 'jackdempsey-acts_as_commentable', :lib => 'acts_as_commentable', :source => "http://gems.github.com"
|
30
|
-
|
31
|
-
|
32
|
-
Generate your comment model:
|
33
|
-
|
34
|
-
script/generate comment
|
35
|
-
|
36
|
-
Then migrate your database:
|
37
|
-
|
38
|
-
rake db:migrate
|
39
|
-
|
40
|
-
== Usage
|
41
|
-
Merb Users:
|
42
|
-
* add 'dependency "acts_as_commentable"' to your init.rb or dependencies.rb if using merb-stack
|
43
|
-
|
44
|
-
* Make your ActiveRecord model act as commentable.
|
45
|
-
|
46
|
-
class Model < ActiveRecord::Base
|
47
|
-
acts_as_commentable
|
48
|
-
end
|
49
|
-
|
50
|
-
* Add a comment to a model instance
|
51
|
-
|
52
|
-
commentable = Model.create
|
53
|
-
commentable.comments.create(:title => "First comment.", :comment => "This is the first comment.")
|
54
|
-
|
55
|
-
* Fetch comments for a commentable model:
|
56
|
-
|
57
|
-
commentable = Model.find(1)
|
58
|
-
comments = commentable.comments.recent.limit(10).all
|
59
|
-
|
60
|
-
# Following doesn't work/make sense to me. Leaving for historical sake -- Jack
|
61
|
-
# * Each comment reference commentable object
|
62
|
-
#
|
63
|
-
# model = Model.find(1)
|
64
|
-
# model.comments.get(0).commentable == model
|
65
|
-
|
66
|
-
== Credits
|
67
|
-
|
68
|
-
Xelipe - This plugin is heavily influenced by Acts As Taggable.
|
69
|
-
|
70
|
-
== More
|
71
|
-
|
72
|
-
http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/
|
73
|
-
http://www.juixe.com/projects/acts_as_commentable
|