Download Facebook-Clone/app/controllers/api/comments_controller.rb from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 815 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Facebook-Clone/app/controllers/api/comments_controller.rb
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/Facebook-Clone/app/controllers/api/comments_controller.rb
-
curl -L -o comments_controller.rb https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Facebook-Clone/app/controllers/api/comments_controller.rb
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 | |