parrot 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,21 +7,33 @@
7
7
  3. Run <tt>rake db:migrate</tt>
8
8
  4. Run <tt>rails g parrot MODEL_NAME</tt>
9
9
  5. Add subresources to routes
10
-
11
- resources RESOURCE_NAME do
12
- resources :parrot_comments, controller: 'parrot/comments', path: 'comments'
13
- end
14
-
15
- 6. Add commenting relation to your commenters:
16
-
17
- has_many :comments, :class_name => Parrot::Comment, :foreign_key => :author_id
10
+ <pre>
11
+ resources RESOURCE_NAME do
12
+ resources :parrot_comments, controller: 'parrot/comments', path: 'comments'
13
+ end
14
+ </pre>
18
15
 
19
16
  # Notes
20
17
 
21
- * By default it calls to_s on commenter name. You may want to alias it to name
22
- for example, so it doesn't show the Ruby "ugly" object.
18
+ Given <tt>@comment = Parrot::Comment.find(id)</tt>:
19
+
20
+ * <tt>rails g parrot MODEL_NAME</tt> (4th step of the installation) adds a
21
+ <tt>parrot_comments</tt> class method in the model. It sets a polymorphic
22
+ relation with <tt>Parrot::Comment</tt>, whose name is <tt>commentable</tt>.
23
+ You can call <tt>@post.comments</tt> to get related comments, or
24
+ <tt>@comment.commentable</tt> to get the related entry of a given comment.
25
+ * The default "author" model is <tt>User</tt>. You may change it from
26
+ <tt>config/initializers/parrot.rb</tt>. You can call
27
+ <tt>@comment.author</tt> to get comment's author.
28
+ * Parrot views calls <tt>to_s</tt> method on the comment's <tt>author</tt>.
29
+ You may want to alias it, or the "ugly" Ruby object will be shown:
30
+ <tt>alias_method :to_s, :name</tt>
31
+ * You may define <tt>after_comment_path</tt> method on commentable model for
32
+ defining where the user should be redirected after commenting (related
33
+ resource by default).
23
34
 
24
35
  # To-do
25
36
 
26
37
  * Flash responders working?
27
- * How to reopen parrot's subclasses from parent applications?
38
+ * Wiki: how to reopen parrot's subclasses from parent applications?
39
+ (<tt>to_prepare</tt>).
@@ -19,18 +19,18 @@ module Parrot
19
19
  @comment.author_id = current_user.id
20
20
  @comment.save
21
21
  @commentable_type = commentable_type
22
- respond_with @comment, :location => commentable
22
+ respond_with @comment, :location => after_comment_path(commentable, @comment)
23
23
  end
24
24
 
25
25
  def destroy
26
26
  @comment = current_user.comments.find params[:id]
27
27
  @comment.destroy
28
- respond_with @comment, :location => commentable
28
+ respond_with @comment, :location => after_comment_path(commentable, @comment)
29
29
  end
30
30
 
31
31
  # Following methods should belong to ApplicationController
32
32
  def commentable_fk
33
- commentable_fk = params.select{|k,v| k =~ /_id/ }.keys.first
33
+ commentable_fk = params.select{|k,v| k =~ /_id/ }.keys.last
34
34
  end
35
35
 
36
36
  def commentable_type
@@ -39,10 +39,10 @@ module Parrot
39
39
 
40
40
  def commentable_id
41
41
  id = params[commentable_fk]
42
- if id.to_i.to_s == id # Numeric id
42
+ if id.to_i.to_s == id # Numeric id?
43
43
  id.to_i
44
44
  else
45
- commentable(id).id # Slugged (text, but we store integers)
45
+ commentable(id).id # Slugged (coming as text, but we need numeric id)
46
46
  end
47
47
  end
48
48
 
@@ -50,6 +50,10 @@ module Parrot
50
50
  commentable_type.classify.constantize.find(id || commentable_id)
51
51
  end
52
52
 
53
+ def after_comment_path(commentable, comment)
54
+ commentable.respond_to?(:after_comment_path) ? commentable.after_comment_path(comment) : commentable
55
+ end
56
+
53
57
  def debug(object)
54
58
  logger.warn "DEBUGGING: #{object.inspect}"
55
59
  end
@@ -1,3 +1,3 @@
1
1
  module Parrot
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -2,6 +2,9 @@ class CreateParrotComments < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :parrot_comments do |t|
4
4
  t.integer :author_id
5
+ t.string :author_name
6
+ t.string :author_email
7
+ t.string :author_phone
5
8
  t.string :commentable_type
6
9
  t.integer :commentable_id
7
10
  t.text :body
@@ -15,6 +15,9 @@ ActiveRecord::Schema.define(:version => 20120429124205) do
15
15
 
16
16
  create_table "parrot_comments", :force => true do |t|
17
17
  t.integer "author_id"
18
+ t.string "author_name"
19
+ t.string "author_email"
20
+ t.string "author_phone"
18
21
  t.string "commentable_type"
19
22
  t.integer "commentable_id"
20
23
  t.text "body"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parrot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-08 00:00:00.000000000 Z
12
+ date: 2012-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70103229606760 !ruby/object:Gem::Requirement
16
+ requirement: &70272666574300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70103229606760
24
+ version_requirements: *70272666574300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70103229606340 !ruby/object:Gem::Requirement
27
+ requirement: &70272666573820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70103229606340
35
+ version_requirements: *70272666573820
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: devise
38
- requirement: &70103229605920 !ruby/object:Gem::Requirement
38
+ requirement: &70272666573380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70103229605920
46
+ version_requirements: *70272666573380
47
47
  description: Add simple comments to any Rails resource.
48
48
  email: tutecosta@gmail.com
49
49
  executables: []