【发布时间】:2016-05-15 15:40:06
【问题描述】:
我有这个json数据(实际数据要长很多,所以我只需要2个)
[
{
"id": 1,
"user_id": 1,
"event_id": 1,
"creator_id": 1,
"event_name": "Poker",
"cruise_ship_name": "Royal Cruise",
},
{
"id": 2,
"user_id": 1,
"event_id": 2,
"creator_id": 1,
"event_name": "Ballroom",
"cruise_ship_name": "Celebrity Infinity",
},
{
"id": 3,
"user_id": 1,
"event_id": 3,
"creator_id": 1,
"event_name": "Tennis",
"cruise_ship_name": "Mediterranean",
}
]
我想合并所有数据并仅获取特定字段(event_name 和 Cruise_ship_name)
所以在我最终的 json 格式中
它将是:
[
{
"event_name": "Mexican Fiesta",
"cruise_ship_name": "Celebrity Infinity",
}
]
我一直在看这个例子:
@object.to_json {:include => [ :assocation_a, :assocation_b ]}
但不确定 :association_a 和 :association_b 是什么。
【问题讨论】:
标签: ruby-on-rails json