New comments can be created

This commit is contained in:
riggraz
2019-09-18 13:40:00 +02:00
parent ecfdc54100
commit 7701c8f5e6
12 changed files with 267 additions and 18 deletions

View File

@@ -15,9 +15,11 @@ class CommentsController < ApplicationController
comment = Comment.new(comment_params)
if comment.save
render json: comment, status: :no_content
render json: comment, status: :created
else
render json: I18n.t('errors.unauthorized'), status: :unauthorized
render json: {
error: I18n.t('errors.comment.create', message: comment.errors.full_messages)
}, status: :unprocessable_entity
end
end
@@ -26,7 +28,7 @@ class CommentsController < ApplicationController
def comment_params
params
.require(:comment)
.permit(:body)
.permit(:body, :parent_id)
.merge(
user_id: current_user.id,
post_id: params[:post_id]