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 呈现XML工作但呈现JSON不工作_Ruby On Rails_Json_Xml_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 呈现XML工作但呈现JSON不工作

Ruby on rails 呈现XML工作但呈现JSON不工作,ruby-on-rails,json,xml,ruby-on-rails-4,Ruby On Rails,Json,Xml,Ruby On Rails 4,正在处理一个简单的rails api,需要返回json,但无法返回。用xml替换json对我来说很有效,代码正确地返回了xml,但没有返回json module Api class AgendaController < ApplicationController respond_to :json def all render json:Person.all end def default_serializer_options

正在处理一个简单的rails api,需要返回json,但无法返回。用xml替换json对我来说很有效,代码正确地返回了xml,但没有返回json

module Api
  class AgendaController < ApplicationController

    respond_to :json

    def all
      render json:Person.all
    end
    def default_serializer_options
      {root:false}
    end
  end
end
错误:

Api::AgendaController#all中的命名错误 未定义的方法“idm”#


请求的格式是什么?如果请求不是json格式的,它不会返回任何内容。只需编辑问题以澄清问题。嗯,我刚刚以您的代码为例编写了一个虚拟应用程序,它似乎工作正常。当您发出请求并在控制器中具有
呈现json:[…]
时,服务器控制台显示什么?您是使用浏览器还是
cURL
或其他什么工具生成请求?尝试这两种方法后,错误保持不变。您可以共享您的应用程序吗?当然可以:
 namespace :api, constraints: {format: :json} do
        get 'people' => 'agenda#all'

  end
 def all
      render json: Person.all #ErrorHere
    end