Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 响应format.json';不要在救援车内工作_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 响应format.json';不要在救援车内工作

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 '

我有以下代码来处理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 'errors/404' , status: 404 }
    end
    true
  end
但是,当接收到JSON请求“Accept:application/JSON,text/plain,/”时,它坚持执行
format.html
块。如果我删除
format.html
块,它会抛出一个
ActionController::UnknownFormat
异常。在这一点上,我被卡住了