Ruby on rails 响应format.json';不要在救援车内工作
我有以下代码来处理ActiveRecord:RecordNotFound异常在我的ApplicationController中Ruby on rails 响应format.json';不要在救援车内工作,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我有以下代码来处理ActiveRecord:RecordNotFound异常在我的ApplicationController中 rescue_from ActiveRecord::RecordNotFound do respond_to do |format| format.json { render json: { message: 'Unable to find record' }, status: 404 } format.html { render '
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
异常。在这一点上,我被卡住了