执行类似这样的操作时,RecordNotFound错误的正确响应应该是什么:
def destroy
@post = current_user.posts.find(params[:id])
@post.destroy
head :no_content
end
答案 0 :(得分:0)
您可以写如下:
def destroy
@post = current_user.posts.find(params[:id])
rescue ActiveRecord::RecordNotFound
flash[:notice] = "Record Not Found"
@post .destroy
head :no_content
end