我正在尝试使用jbuilder
如下所示的 JSON 输出:
[{"correct_response": 0,
"section_id": 1,
"image_url": "https://850.s3.amazonaws.com/uploads/question/3/PreguntaWeb.png?AWSAccessKeyId=AKIAJSKXBBJ4URBWSPUQ&Signature=r8COJLWNWABfwlm6BQ4ZpPlvFGw%3D&Expires=1401509509",
"responses": [{
"responseA": "https://850.s3.amazonaws.com/uploads/response/1/alternativaA.png?AWSAccessKeyId=AKIAJSKXBBJ4URBWSPUQ&Signature=MkUUT7NuoHDH/BjiJdMiHV5f%2BB4%3D&Expires=1401509509"},
{"responseB": "https://850.s3.amazonaws.com/uploads/response/2/alternativaB.png?AWSAccessKeyId=AKIAJSKXBBJ4URBWSPUQ&Signature=EZ6KeqhzlwPGX1PAetvqR/GPH2M%3D&Expires=1401509509"},
{"responseC": "https://850.s3.amazonaws.com/uploads/response/3/alternativaC.png?AWSAccessKeyId=AKIAJSKXBBJ4URBWSPUQ&Signature=/Ntt6y4JrfVjjw0zpOKgIXtihvI%3D&Expires=1401509509"},
{"responseD": "https://850.s3.amazonaws.com/uploads/response/4/alternativaD.png?AWSAccessKeyId=AKIAJSKXBBJ4URBWSPUQ&Signature=Exrr0WTsSx2n3FixjwADiiwwPjM%3D&Expires=1401509509"},
{"responseAE": "https://850.s3.amazonaws.com/uploads/response/5/alternativaE.png?AWSAccessKeyId=AKIAJSKXBBJ4URBWSPUQ&Signature=udJ5jK/zG9ug8A6WwsnhYZRcsPk%3D&Expires=1401509509"}
]
}]
我想我已经接近了,但我不知道我的代码有什么问题:
json.array!(@questions) do |json, question|
json.extract! question, :correct_response, :section_id, :image_url
json.responses question.responses do |response|
[ 'responseA', 'responseB', 'responseC', 'responseD', 'responseE' ].each { |letter|
response.set!(letter, response.image_url )
}
end
end
end
有人有什么建议吗?