Post#update 要能更新單筆文章
module ApiV0
class Posts < Grape::API
# ...
desc "Update post"
params do
requires :id, type: String, desc: 'Post ID.'
requires :title, type: String, desc: "Post title"
requires :context, type: String, desc: "Post context"
end
patch "/posts/:id" do
post = current_user.posts.find_by(id: params[:id])
if post.update(declared(params, include_missing: false).except(:access_key))
present post, with: ApiV0::Entities::Post
else
raise StandardError, $!
end
end
# ...
end
end