Class: Comment::CommentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Comment::CommentsController
- Defined in:
- app/controllers/comment/comments_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /comments.
-
#destroy ⇒ Object
DELETE /comments/1.
-
#index ⇒ Object
GET /comments.
- #reply ⇒ Object
-
#update ⇒ Object
PATCH/PUT /comments/1.
Instance Method Details
#create ⇒ Object
POST /comments
11 12 13 14 15 |
# File 'app/controllers/comment/comments_controller.rb', line 11 def create @comment = Comment.new(comment_params) @comment.user_id = current_user.id @comment.save end |
#destroy ⇒ Object
DELETE /comments/1
28 29 30 31 32 33 34 |
# File 'app/controllers/comment/comments_controller.rb', line 28 def destroy if @comment.user_id != current_user.id raise ActiveRecord::RecordNotFound end @comment.destroy end |
#index ⇒ Object
GET /comments
6 7 8 |
# File 'app/controllers/comment/comments_controller.rb', line 6 def index @comments = Comment.order('id asc').page(params[:page]) end |
#reply ⇒ Object
22 23 24 25 |
# File 'app/controllers/comment/comments_controller.rb', line 22 def reply @parent = Comment.find(params[:id]) @comment = Comment.new(parent_id: @parent.id, commentable: @parent.commentable) end |
#update ⇒ Object
PATCH/PUT /comments/1
18 19 20 |
# File 'app/controllers/comment/comments_controller.rb', line 18 def update @success = @comment.update(comment_params) end |