Download app/controllers/api/v1/comments_controller.rb from denise-oneill-inbox-ru/Rails-8-API-Image-Processing: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/resolve/main/app/controllers/api/v1/comments_controller.rb
- Command line
-
hf download hf://spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/app/controllers/api/v1/comments_controller.rb
-
curl -L -o comments_controller.rb https://huggingface.co/spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/resolve/main/app/controllers/api/v1/comments_controller.rb
1 kB
| module Api | |
| module V1 | |
| class CommentsController < BaseController | |
| before_action :set_post | |
| def index | |
| comments = @post.comments.kept.includes(:user).order(created_at: :desc) | |
| @pagy, comments = pagy(comments, items: 20) | |
| render json: CommentBlueprint.render(comments), | |
| meta: pagy_metadata(@pagy) | |
| end | |
| def create | |
| comment = @post.comments.build(comment_params) | |
| comment.user = current_user | |
| authorize comment | |
| if comment.save | |
| render json: CommentBlueprint.render(comment), status: :created | |
| else | |
| render json: { errors: comment.errors.full_messages }, status: :unprocessable_entity | |
| end | |
| end | |
| private | |
| def set_post | |
| @post = Post.friendly.find(params[:post_slug]) | |
| end | |
| def comment_params | |
| params.require(:comment).permit(:content) | |
| end | |
| def action_allows_anonymous? | |
| action_name == "index" | |
| end | |
| end | |
| end | |
| end | |