Ruby on rails 如何使用JBuilder Rails在同一JSON对象中编码2个对象
使用JBuilder有以下代码:Ruby on rails 如何使用JBuilder Rails在同一JSON对象中编码2个对象,ruby-on-rails,jbuilder,Ruby On Rails,Jbuilder,使用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}]} 现在我需要将食物类型转移到细节: details":{"average_c
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}]}
现在我需要将食物类型转移到细节:
details":{"average_check":100,"id":12", food_types":[{"id":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
或者你可以这样建造它
json.details do
json.(place.details, :average_check, :id)
if (place.type == 'restaurant')
json.food_types place.details.food_types, :id
end
end
end
或