parrot 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,6 +25,7 @@ Given <tt>@comment = Parrot::Comment.find(id)</tt>:
25
25
  * The default "author" model is <tt>User</tt>. You may change it from
26
26
  <tt>config/initializers/parrot.rb</tt>. You can call
27
27
  <tt>@comment.author</tt> to get comment's author.
28
+ * User model: `has_many :comments, class_name: Parrot::Comment, foreign_key: :author_id`
28
29
  * Parrot views calls <tt>to_s</tt> method on the comment's <tt>author</tt>.
29
30
  You may want to alias it, or the "ugly" Ruby object will be shown:
30
31
  <tt>alias_method :to_s, :name</tt>
@@ -34,6 +35,13 @@ Given <tt>@comment = Parrot::Comment.find(id)</tt>:
34
35
 
35
36
  # To-do
36
37
 
38
+ * Show partial views examples for showing existing comments and comment form
37
39
  * Flash responders working?
38
40
  * Wiki: how to reopen parrot's subclasses from parent applications?
39
41
  (<tt>to_prepare</tt>).
42
+
43
+ ----
44
+
45
+ ![Chef Surfing](https://chefsurfing.com/images/embed/logos/chef_surfing_header_logo_medium_red.png)
46
+
47
+ parrot is maintained and funded by [Chef Surfing](https://chefsurfing.com/)
@@ -3,7 +3,7 @@ module Parrot
3
3
  respond_to :html
4
4
 
5
5
  def index
6
- @comments = Comment.where(commentable_type: commentable_type.classify, commentable_id: commentable_id)
6
+ @comments = Comment.where(commentable_type: commentable_type, commentable_id: commentable_id)
7
7
  respond_with @comments
8
8
  end
9
9
 
@@ -14,7 +14,7 @@ module Parrot
14
14
 
15
15
  def create
16
16
  @comment = Comment.new(params[:parrot_comment])
17
- @comment.commentable_type = commentable_type.classify
17
+ @comment.commentable_type = commentable_type
18
18
  @comment.commentable_id = commentable_id
19
19
  @comment.author_id = current_user.id
20
20
  @comment.save
@@ -25,16 +25,24 @@ module Parrot
25
25
  def destroy
26
26
  @comment = current_user.comments.find params[:id]
27
27
  @comment.destroy
28
+ params[:commentable_type] = @comment.commentable_type # Set commentable_type param (maybe namespaced for example)
28
29
  respond_with @comment, :location => after_comment_path(commentable, @comment)
29
30
  end
30
31
 
32
+
33
+ private
34
+
31
35
  # Following methods should belong to ApplicationController
32
36
  def commentable_fk
33
37
  commentable_fk = params.select{|k,v| k =~ /_id/ }.keys.last
34
38
  end
35
39
 
36
40
  def commentable_type
37
- commentable_fk.gsub('_id', '')
41
+ if params[:commentable_type].present?
42
+ params[:commentable_type]
43
+ else
44
+ commentable_fk.gsub('_id', '')
45
+ end
38
46
  end
39
47
 
40
48
  def commentable_id
@@ -47,7 +55,7 @@ module Parrot
47
55
  end
48
56
 
49
57
  def commentable(id = nil)
50
- commentable_type.classify.constantize.find(id || commentable_id)
58
+ commentable_type.constantize.find(id || commentable_id)
51
59
  end
52
60
 
53
61
  def after_comment_path(commentable, comment)
@@ -17,6 +17,7 @@
17
17
  <%= f.text_area :body %>
18
18
  </div>
19
19
  <div class="actions">
20
+ <%= hidden_field_tag :commentable_type, comment.commentable.class %>
20
21
  <%= f.submit t('parrot.send_comment'), class: 'btn btn-success' %>
21
22
  </div>
22
23
  <% end %>
@@ -1,3 +1,3 @@
1
1
  module Parrot
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
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.3
4
+ version: 0.0.4
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-22 00:00:00.000000000 Z
12
+ date: 2012-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70272666574300 !ruby/object:Gem::Requirement
16
+ requirement: &70122610604020 !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: *70272666574300
24
+ version_requirements: *70122610604020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70272666573820 !ruby/object:Gem::Requirement
27
+ requirement: &70122610603600 !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: *70272666573820
35
+ version_requirements: *70122610603600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: devise
38
- requirement: &70272666573380 !ruby/object:Gem::Requirement
38
+ requirement: &70122610603180 !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: *70272666573380
46
+ version_requirements: *70122610603180
47
47
  description: Add simple comments to any Rails resource.
48
48
  email: tutecosta@gmail.com
49
49
  executables: []