Class: Comments::CommentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Comments::CommentsController
- Defined in:
- app/controllers/comments/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.
Methods inherited from ApplicationController
#authenticate_user!, #current_user
Instance Method Details
#create ⇒ Object
POST /comments
12 13 14 15 16 |
# File 'app/controllers/comments/comments_controller.rb', line 12 def create @comment = Comment.new(comment_params) @comment.user = current_user @comment.save end |
#destroy ⇒ Object
DELETE /comments/1
29 30 31 32 33 34 35 |
# File 'app/controllers/comments/comments_controller.rb', line 29 def destroy if @comment.user_id != current_user.id raise ActiveRecord::RecordNotFound end @comment.destroy end |
#index ⇒ Object
GET /comments
7 8 9 |
# File 'app/controllers/comments/comments_controller.rb', line 7 def index @comments = Comment.order('id asc').page(params[:page]) end |
#reply ⇒ Object
23 24 25 26 |
# File 'app/controllers/comments/comments_controller.rb', line 23 def reply @parent = Comment.find(params[:id]) @comment = Comment.new(parent_id: @parent.id, commentable: @parent.commentable) end |
#update ⇒ Object
PATCH/PUT /comments/1
19 20 21 |
# File 'app/controllers/comments/comments_controller.rb', line 19 def update @success = @comment.update(comment_params) end |