当做这样的事情时,RecordNotFound错误的正确响应应该是什么:
def destroy
@post = current_user.posts.find(params[:id])
@post.destroy
head :no_content
end
你可以这样写:
def destroy
@post = current_user.posts.find(params[:id])
rescue ActiveRecord::RecordNotFound
flash[:notice] = "Record Not Found"
@post .destroy
head :no_content
end