使用JBuilder有以下代码:
json.details place.details
if (place.type == 'restaurant')
json.food_types place.details.food_types, :id
end
JSON回复:
details":{"average_check":100,"id":12},"food_types":[{"id":1}]}
现在我需要将food_types移动到细节:
details":{"average_check":100,"id":12", food_types":[{"id":1}]}}
我该怎么做?
答案 0 :(得分:1)
你可以像这样构建它
json.details do
json.(place.details, :average_check, :id)
if (place.type == 'restaurant')
json.food_types place.details.food_types, :id
end
end
end
或Jbuilder objects can be directly nested inside each other. Useful for composing objects.