You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
712 B

  1. class PostsController < ApplicationController
  2. before_action :set_post, only: [:show, :good, :bad, :destroy]
  3. def show
  4. render json: @post.as_json.merge(image_url: (
  5. if @post.image.attached?
  6. Rails.application.routes.url_helpers.rails_blob_url(@post.image, only_path: true)
  7. else
  8. nil
  9. end))
  10. end
  11. # POST /posts/:id/good
  12. def good
  13. @post.increment!(:good)
  14. head :no_content
  15. end
  16. # POST /posts/:id/bad
  17. def bad
  18. @post.increment!(:bad)
  19. head :no_content
  20. end
  21. # DELETE /posts/:id
  22. def destroy
  23. @post.update!(deleted_at: Time.current)
  24. head :no_content
  25. end
  26. private
  27. def set_post
  28. @post = Post.active.find(params[:id])
  29. end
  30. end