1

我想以 json 格式查看以下代码。当我这样做时,我得到一个没有内容的空白页面。在 ruby​​mine 调试器中,我有 json 格式的正确信息。

include Java

require 'net/http'

class PatientRecordController < ApplicationController

  def index
    url = 'http://localhost:8080/patient/record/v2/'
    data_raw = Net::HTTP.get_response(URI.parse(url)).body

    @data_json = ActiveSupport::JSON.decode(data_raw)

    respond_to do |format|
      format.json {render json: @data_json}
    end

  end
end
4

3 回答 3

3

您必须.json在输入浏览器的路径末尾添加。

于 2013-06-10T18:36:10.463 回答
0

如果您不想将请求更改为包含 .json,则可以render json: @data_json自行删除 respond_to 块即可。

于 2013-06-10T19:46:24.310 回答
0

这个特定index动作的路径是什么?此代码确实应该呈现 JSON,您的调试器表明它确实如此。

您应该访问的 URL 类似于http://your_host/patient_records/index.json.

于 2013-06-10T18:54:11.397 回答