我有以下代码来处理ActiveRecord:我的ApplicationController中的RecordNotFound异常
rescue_from ActiveRecord::RecordNotFound do
respond_to do |format|
format.json { render json: { message: 'Unable to find record' }, status: 404 }
format.html { render 'errors/404' , status: 404 }
end
true
end
但是,当收到JSON请求“Accept:application / json,text / plain, / ”时,它仍然坚持执行format.html
块。如果我删除format.html
块,则会引发ActionController::UnknownFormat
异常。此时我被困住了。