rails json响应无法构建

时间:2016-07-08 08:58:26

标签: ruby-on-rails json

我在控制器创建中有一个方法

它会生成像

这样的记录数组
[{"code"=>500, "body"=>{"message"=>"Ivalid data or you enter a duplicate data"}}, {"code"=>200, "body"=>{"id"=>"775606be-d3ae-4b43-a820-74022f8f273f"}}, {"code"=>500, "body"=>{"message"=>["Name has already been taken"]}}, {"code"=>500, "body"=>{"message"=>[:Error, ["No Fable", "level not found in rand", "Invalid or Blank e"]]}}]

现在我想让它成为一个json响应

def create
   k=[{"code"=>500, "body"=>{"message"=>"Ivalid data or you enter a duplicate data"}}, {"code"=>200, "body"=>{"id"=>"775606be-d3ae-4b43-a820-74022f8f273f"}}, {"code"=>500, "body"=>{"message"=>["Name has already been taken"]}}, {"code"=>500, "body"=>{"message"=>[:Error, ["No Federation ID in Cookie ID\n# Mapping Table", "level not found in Brand", "Invalid or Blank Source Type"]]}}]
    # render create.json.jbuilder
    render json: k, status: 200
  end

所以它生成

{
  "bulks": [
    {
      "code": 500,
      "body": {
        "message": "Ivalid data or you enter a duplicate data"
      }
    },
    {
      "code": 200,
      "body": {
        "id": "7754322222222f"
      }
    },
    {
      "code": 500,
      "body": {
        "message": [
          "Name has already been taken"
        ]
      }
    },
    {
      "code": 500,
      "body": {
        "message": [
          "Error",
          [
            "No Fable",
            "level not found in Brand",
            "Invalid or Blank Source Type"
          ]
        ]
      }
    }
  ]

}

在控制器

中渲染json时添加了bulks:

如何删除bulks预期的json

{   {
          "code": 500,
          "body": {
            "message": "Ivalid data or you enter a duplicate data"
          }
        },
        {
          "code": 200,
          "body": {
            "id": "775606be-d3ae-4b43-a820-74022f8f273f"
          }
        },
        {
          "code": 500,
          "body": {
            "message": [
              "Name has already been taken"
            ]
          }
        },
        {
          "code": 500,
          "body": {
            "message": [
              "Error",
              [
                "No Fable",
                "level not found in Brand",
                "Invalid or Blank Source Type"
              ]
            ]
          }
        } }

请帮忙

0 个答案:

没有答案