Class: Parrot::CommentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Parrot::CommentsController
- Defined in:
- app/controllers/parrot/comments_controller.rb
Instance Method Summary collapse
- #commentable(id = nil) ⇒ Object
-
#commentable_fk ⇒ Object
Following methods should belong to ApplicationController.
- #commentable_id ⇒ Object
- #commentable_type ⇒ Object
- #create ⇒ Object
- #debug(object) ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#commentable(id = nil) ⇒ Object
49 50 51 |
# File 'app/controllers/parrot/comments_controller.rb', line 49 def commentable(id = nil) commentable_type.classify.constantize.find(id || commentable_id) end |
#commentable_fk ⇒ Object
Following methods should belong to ApplicationController
32 33 34 |
# File 'app/controllers/parrot/comments_controller.rb', line 32 def commentable_fk commentable_fk = params.select{|k,v| k =~ /_id/ }.keys.first end |
#commentable_id ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/parrot/comments_controller.rb', line 40 def commentable_id id = params[commentable_fk] if id.to_i.to_s == id # Numeric id id.to_i else commentable(id).id # Slugged (text, but we store integers) end end |
#commentable_type ⇒ Object
36 37 38 |
# File 'app/controllers/parrot/comments_controller.rb', line 36 def commentable_type commentable_fk.gsub('_id', '') end |
#create ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/parrot/comments_controller.rb', line 15 def create @comment = Comment.new(params[:parrot_comment]) @comment.commentable_type = commentable_type.classify @comment.commentable_id = commentable_id @comment. = current_user.id @comment.save @commentable_type = commentable_type respond_with @comment, :location => commentable end |
#debug(object) ⇒ Object
53 54 55 |
# File 'app/controllers/parrot/comments_controller.rb', line 53 def debug(object) logger.warn "DEBUGGING: #{object.inspect}" end |
#destroy ⇒ Object
25 26 27 28 29 |
# File 'app/controllers/parrot/comments_controller.rb', line 25 def destroy @comment = current_user.comments.find params[:id] @comment.destroy respond_with @comment, :location => commentable end |
#index ⇒ Object
5 6 7 8 |
# File 'app/controllers/parrot/comments_controller.rb', line 5 def index @comments = Comment.where(commentable_type: commentable_type.classify, commentable_id: commentable_id) respond_with @comments end |
#new ⇒ Object
10 11 12 13 |
# File 'app/controllers/parrot/comments_controller.rb', line 10 def new @comment = Comment.new respond_with @comment end |