Post#destroy 要能刪除單筆文章

module ApiV0
  class Posts < Grape::API
    # ...

    desc "Delete a post."
    params do
      requires :id, type: String, desc: 'Post ID.'
    end
    delete "/posts/:id" do
      post = current_user.posts.find_by(id: params[:id])

      if post.destroy
        present post, with: ApiV0::Entities::Post
      else
        raise StandardError, $!
      end
    end

    # ...
  end
end
Copyright © NicLin 2019 all right reserved,powered by Gitbook該頁面生成時間: 2019-04-09 10:00:37

results matching ""

    No results matching ""