Class: Unsakini::CommentsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Unsakini::CommentsController
- Includes:
- ActionController::Serialization, CommentOwnerControllerConcern, LoggedInControllerConcern, PostOwnerControllerConcern
- Defined in:
- app/controllers/unsakini/comments_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Creates new comment belonging to the post.
-
#destroy ⇒ Object
Deletes a comment.
-
#index ⇒ Object
Renders the comments belonging to the post.
-
#update ⇒ Object
Updates a comment.
Methods included from CommentOwnerControllerConcern
#ensure_comment, #ensure_comment_owner, #has_comment_access
Methods included from PostOwnerControllerConcern
#ensure_post, #ensure_post_owner, #has_post_access
Instance Method Details
#create ⇒ Object
Creates new comment belonging to the post
‘POST /api/boards/:board_id/posts/:post_id/`
23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/unsakini/comments_controller.rb', line 23 def create @comment = Comment.new(params.permit(:content)) @comment.user = @user @comment.post = @post if @comment.save render json: @comment else render json: @comment.errors, status: 422 end end |
#destroy ⇒ Object
Deletes a comment
‘DELETE /api/boards/:board_id/posts/:post_id/comments/:id`
48 49 50 51 |
# File 'app/controllers/unsakini/comments_controller.rb', line 48 def destroy @comment.destroy render json: {}, status: :ok end |
#index ⇒ Object
Renders the comments belonging to the post
‘GET /api/boards/:board_id/posts/:post_id/`
16 17 18 |
# File 'app/controllers/unsakini/comments_controller.rb', line 16 def index paginate json: @post.comments.page(params[:page]), per_page: 20 end |
#update ⇒ Object
Updates a comment
‘PUT /api/boards/:board_id/posts/:post_id/comments/:id`
37 38 39 40 41 42 43 |
# File 'app/controllers/unsakini/comments_controller.rb', line 37 def update if @comment.update(params.permit(:content)) render json: @comment else render json: @comment.errors, status: 422 end end |