我有一个带有"active_model_serializers“创业板的rails api。
http://localhost:3000/api/buildings/30.json为我生成了以下内容:
{
building:{
id:30,
city_name:"msc",
infrastructure:[
{
id:40,
name:"name 1",
created_at:"2015-07-30T08:26:49.000Z",
updated_at:"2015-07-30T08:26:49.000Z"
},
{
id:69,
name:"name 2",
created_at:"2015-07-30T08:26:50.000Z",
updated_at:"2015-07-30T08:26:50.000Z"
},
{
id:39,
name:"name 3",
created_at:"2015-07-30T08:26:49.000Z",
updated_at:"2015-07-30T08:26:49.000Z"
}
]
}
}此外,我在ActiveModelAdapter中使用EmberJs。但安博预计:
{
building:{
id:30,
city_name:"msc",
infrastructure:[
40,
69,
39
]
},
infrastructure:[
{
id:40,
name:"name 1",
created_at:"2015-07-30T08:26:49.000Z",
updated_at:"2015-07-30T08:26:49.000Z"
},
{
id:69,
name:"name 2",
created_at:"2015-07-30T08:26:50.000Z",
updated_at:"2015-07-30T08:26:50.000Z"
},
{
id:39,
name:"name 3",
created_at:"2015-07-30T08:26:49.000Z",
updated_at:"2015-07-30T08:26:49.000Z"
}
]
}我如何使成员与rails json结构一起工作?谢谢!
发布于 2015-08-13 00:55:10
另一种选择是走JSON路线。
我觉得这是个更好的选择
我在http://emberigniter.com/modern-bridge-ember-and-rails-5-with-json-api/ (对于Rails 5)上写了一个指南,但是您肯定可以将它改编成您的Rails版本。
发布于 2015-08-12 12:46:07
您需要在Ember端使用嵌入式记录Mixin。
App.ColorSerializer = DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
foos: {embedded: 'always'}
}
});查看这个答案
https://stackoverflow.com/questions/31965410
复制相似问题