In the Ember guide on models http://emberjs.com/guides/models/the-rest-adapter/#toc_relationships I see that associations should be specified as an array of ids:
{
“post”: {
“comments”: [1, 2, 3]
}
}
I’m having trouble working out how to generate the array of ids in the rails controller. While I can :include the associated models, they are included as an array of hashes:
{“name”:”Jane’s Place”,”rooms”:[{“id”:1},{“id”:2},{“id”:3}]}
Any ideas on how one would get the array form?
Ember recommends using the active_model_serializers gem to generate JSON in a compatible format.
Here is an example from the active_model_serializer documentation to do pretty much exactly what you’re asking. The
embed :idsis the key.https://github.com/rails-api/active_model_serializers