Devendra174's picture
Upload folder using huggingface_hub
f5071ca verified
raw
history blame contribute delete
815 Bytes
class Api::CommentsController < ApplicationController
def create
@comment = Comment.new(comment_params)
if @comment.save
@post = @comment.post
render "api/posts/show"
else
render json: @comment.errors.full_messages
end
end
def index
@post = Post.find(params[:id])
@comments = @post.comments
end
def update
@comment = Comment.find(params[:id])
if @comment.update_attributes(comment_params)
@post = @comment.post
render "api/posts/show"
else
render json: @comment.errors.full_messages
end
end
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
@post = @comment.post
render "api/posts/show"
end
def comment_params
params.require(:comment).permit(:author_id, :post_id, :body)
end
end